473,473 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

uploading an audio(mp3) file in php?

127 New Member
i am uploading an audio file to a particular folder..

its my form:

Expand|Select|Wrap|Line Numbers
  1. <form action="upload.php" method="post" enctype="multipart/form-data">
  2. <label for="file"><span>Filename:</span></label>
  3. <input type="file" name="file" id="file" /> 
  4. <br />
  5. <input type="submit" name="submit" value="Submit" />
  6. </form>
its my upload.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $allowedExts = array("jpg", "jpeg", "gif", "png", "mp3", "mp4", "wma");
  4. $extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
  5.  
  6. if ((($_FILES["file"]["type"] == "video/mp4")
  7. || ($_FILES["file"]["type"] == "audio/mp3")
  8. || ($_FILES["file"]["type"] == "audio/wma")
  9. || ($_FILES["file"]["type"] == "image/pjpeg")
  10. || ($_FILES["file"]["type"] == "image/gif")
  11. || ($_FILES["file"]["type"] == "image/jpeg"))
  12.  
  13. && ($_FILES["file"]["size"] < 200000)
  14. && in_array($extension, $allowedExts))
  15.  
  16.   {
  17.   if ($_FILES["file"]["error"] > 0)
  18.     {
  19.     echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
  20.     }
  21.   else
  22.     {
  23.     echo "Upload: " . $_FILES["file"]["name"] . "<br />";
  24.     echo "Type: " . $_FILES["file"]["type"] . "<br />";
  25.     echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
  26.     echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
  27.  
  28.     if (file_exists("upload/" . $_FILES["file"]["name"]))
  29.       {
  30.       echo $_FILES["file"]["name"] . " already exists. ";
  31.       }
  32.     else
  33.       {
  34.       move_uploaded_file($_FILES["file"]["tmp_name"],
  35.       "upload/" . $_FILES["file"]["name"]);
  36.       echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
  37.       }
  38.     }
  39.   }
  40. else
  41.   {
  42.   echo "Invalid file";
  43.   }
  44. ?>
the code works fine for images when i add audio file (mp3) i will get 'Invalid file" error.. the images uploaded to the upload folder without any problem.

whats wrong in the code???
Dec 10 '13 #1
1 38765
Mukesh9023
11 New Member
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // make a folder upload to move your file.I yhink this code is necessary to modified but right now it working correctly.
  3. if(isset($_POST['submit']))
  4. {
  5. $allowedExts = array("jpg", "jpeg", "gif", "png", "mp3", "mp4", "wma");
  6. //echo $extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
  7. $fileName = $_FILES['file']['name'];
  8. $extension = substr($fileName, strrpos($fileName, '.') + 1); // getting the info about the image to get its extension
  9.  
  10. /*if ((($_FILES["file"]["type"] == "video/mp4")|| ($_FILES["file"]["type"] == "audio/mp3")|| ($_FILES["file"]["type"] == "audio/wma")|| ($_FILES["file"]["type"] == "image/pjpeg")|| ($_FILES["file"]["type"] == "image/gif")|| ($_FILES["file"]["type"] == "image/jpeg")) && ($_FILES["file"]["size"] < 200000) && in_array($extension, $allowedExts))*/
  11.  
  12. if(in_array($extension, $allowedExts))
  13.   {
  14.   if ($_FILES["file"]["error"] > 0)
  15.     {
  16.      echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
  17.     }
  18.   else
  19.     {
  20.     echo "Upload: " . $_FILES["file"]["name"] . "<br />";
  21.     echo "Type: " . $_FILES["file"]["type"] . "<br />";
  22.     echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
  23.     echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
  24.  
  25.     if (file_exists("upload/" . $_FILES["file"]["name"]))
  26.       {
  27.         echo $_FILES["file"]["name"] . " already exists. ";
  28.       }
  29.     else
  30.       {
  31.        move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $_FILES["file"]["name"]);
  32.       echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
  33.       }
  34.     }
  35.   }
  36. else
  37.   {
  38.   echo "Invalid file";
  39.   }
  40. }
  41. ?>
  42. <form method="post"  enctype="multipart/form-data" >
  43.  
  44. <label for="file"><span>Filename:</span></label>
  45.  
  46. <input type="file" name="file" id="file" /> 
  47.  
  48. <br />
  49. <input type="submit" name="submit" value="Submit" />
  50. </form>
Dec 13 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Saurabh | last post by:
Hi all, I am using php3. For uploading a file i put <input type=file name=thesisfile> in the html file. now in the php3 file that i am using i used echo $thesisfile_type; echo...
1
by: Thorsten Wienbarg | last post by:
Hi there, after doing some reading on this subject, I found lots of information on how to actually avoid not uploading a file. They don't tell me how to exclude the contents of a file though. ...
1
by: HNguyen | last post by:
Access denied error while uploading a file to a web server. I am getting the following error while trying to upload a file to our web server: Error: Access to the path...
1
by: David | last post by:
Hello. I can't upload large file with HtmlInputFile control:( Is there any file size limitation in HtmlInputFile control? If yes how can I upload to server large size file? Than you.
1
by: adaikkalasamy | last post by:
Hi Friends, Colud any of u help me out in this work? How do u validate before uploading, a file is in MS-Word Format or not ? I want to do it in Java. If a file is not a MS word file,...
1
by: recordlovelife | last post by:
Hi all. I need to make a file uploader, so a client can upload pictures to a directory on their shared server, so that they can later include the photos in news updates. I simply want to take...
2
by: Bremanand | last post by:
Hi folks, i am working in C# , i have problem while uploading the file to FTP which has size around 4MB. The code which comes after the bold area is not executed.. here am...
3
by: =?Utf-8?B?UGF1bA==?= | last post by:
I need to programatically upload a text file to a web server using the HTTPWebRequest object within .Net 2.0. So far, I have determined that: - I need a HTTP content-type of...
5
by: arcticmouse | last post by:
this is probably a total newbie question, but i can seem to figure it out. when i run this code it gives me this error: Undefined index: work in FILENAME on line 3... which is the...
3
by: chrisindfw | last post by:
I am uploading a file to a mysql database table. Now let me say that this works perfectly fine for PDF, XLS, and DOC files. However if I upload an XLSX (office 2007 file), it uploads fine, however...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.