954,585 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Mp3 file upload problem

Hi frnds...


i m trying to upload mp3 file ..this is my code..

upload_max_filesize = 20M;//in php.ini
$tname = $_FILES["tphoto"]["name"];
$ttmp_name = $_FILES["tphoto"]["tmp_name"];

 //Audio File Uploading....  
 if($_FILES['tphoto']['type'] == 'audio/mpeg'){
 $dir="../../music/$aid";
 move_uploaded_file($ttmp_name,"$dir"."/"."$tname");
 }


it displays no error...but, no output.

can any body give me some suggestion plz...

Thanks in advance...
Sari K

sarithak
Junior Poster
183 posts since Aug 2008
Reputation Points: 10
Solved Threads: 7
 

check if this is in your form -
enctype="multipart/form-data"

network18
Practically a Master Poster
619 posts since Sep 2009
Reputation Points: 29
Solved Threads: 76
 
check if this is in your form - enctype="multipart/form-data"


Hi ,

Thanks 4 ur reply...

it works fine for all (images, WMA)....when i change the below code..

$_FILES['tphoto']['type'] == 'audio/wma'


....


prob only for MP3 files...

sarithak
Junior Poster
183 posts since Aug 2008
Reputation Points: 10
Solved Threads: 7
 

if you check against that type only, its obvious that script will allow only that file type.
Maybe you are looking for "audio/x-mpeg-3" as file type.

network18
Practically a Master Poster
619 posts since Sep 2009
Reputation Points: 29
Solved Threads: 76
 
sarithak
Junior Poster
183 posts since Aug 2008
Reputation Points: 10
Solved Threads: 7
 
if you check against that type only, its obvious that script will allow only that file type. Maybe you are looking for "audio/x-mpeg-3" as file type.


hifile type= "MP3 formate sound"; //file type ..

i need to allow only MP3 FILES.....

Is there any other parameters change in PHP.INI??...

sarithak
Junior Poster
183 posts since Aug 2008
Reputation Points: 10
Solved Threads: 7
 
a


then why you not using straightaway
$_FILES["file"]["type"] == "audio/mp3";

network18
Practically a Master Poster
619 posts since Sep 2009
Reputation Points: 29
Solved Threads: 76
 
then why you not using straightaway $_FILES["file"]["type"] == "audio/mp3";


Hi ..

I m sorry....

when i m write the if condition..its not working for all types..

if (($_FILES["tphoto"]["type"] == "audio/wma")){


with out condition it works fine except for MP3....

sarithak
Junior Poster
183 posts since Aug 2008
Reputation Points: 10
Solved Threads: 7
 

By using this "if loop " , you actually what is the file type, and if the file type is the specified one then allow the process else do something else.
I think why to use it, must be clear to you by this now.
And you saying when you not using this if loop you are able to upload all the files except the MP3, maybe with this MP3 file you are violating the file size limit.
echo your file element and post it's contents here with this file

network18
Practically a Master Poster
619 posts since Sep 2009
Reputation Points: 29
Solved Threads: 76
 

Hi ..


now i m trying for 5 mb MP3 file...its uploaded perfectly....So, the prob with file size...but in my php.ini

upload_max_size=20M

plz tell me wat i have to do...

Thanks a lot..

sarithak
Junior Poster
183 posts since Aug 2008
Reputation Points: 10
Solved Threads: 7
 

try with another mp3 file having small size and post your entire code here.
and you seem to be confused, first decide which file types you want to restrict and which file types you want to allow.accordingly we will proceed with the code.

network18
Practically a Master Poster
619 posts since Sep 2009
Reputation Points: 29
Solved Threads: 76
 
try with another mp3 file having small size and post your entire code here. and you seem to be confused, first decide which file types you want to restrict and which file types you want to allow.accordingly we will proceed with the code.


hi...

this is my code...its working fine for all(including MP3)...but upto 5MB files only uploaded..8,9,11MB files are not uploaded..

$aid =  mysql_real_escape_string($_POST['albumname']);
$song =  mysql_real_escape_string($_POST['song']);
$singers =  mysql_real_escape_string($_POST['singers']);
$tname = mysql_real_escape_string($_FILES["tphoto"]["name"]);
$ttmp_name = $_FILES["tphoto"]["tmp_name"];

 //Audio File Uploading....  
//if (($_FILES["tphoto"]["type"] == "*.MP3")){ //not working when i use if condition..
 $dir="../../music/$aid";
 move_uploaded_file($ttmp_name,"$dir"."/"."$tname");
 

$sql="insert into music_songs values('','$aid','$song','$singers','$tname')";
$res=mysql_query($sql)or die(mysql_error());
 
//}


another one...now i m working on localhost....

sarithak
Junior Poster
183 posts since Aug 2008
Reputation Points: 10
Solved Threads: 7
 

is "audio/mp3" and "MP3" same for you ?

network18
Practically a Master Poster
619 posts since Sep 2009
Reputation Points: 29
Solved Threads: 76
 
is "audio/mp3" and "MP3" same for you ?


HI..

this is not same....by mistake i put the code as ( *.MP3)... basically i checked for (audio/mp3)...its not working when i put condition there...not only for MP3...
its not working for all types of files when i use if conditon..k...also plz tell me how can i solve the MAX SIZE problem ..

sarithak
Junior Poster
183 posts since Aug 2008
Reputation Points: 10
Solved Threads: 7
 

Again you seem to be confused.This time you are having problem with all the file types.
The max size can be set in the php.ini as, search for "upload_max_filesize" .It may have default value of 2MB at the moment edit it to have whatever you like.

network18
Practically a Master Poster
619 posts since Sep 2009
Reputation Points: 29
Solved Threads: 76
 
Again you seem to be confused.This time you are having problem with all the file types. The max size can be set in the php.ini as, search for "upload_max_filesize" .It may have default value of 2MB at the moment edit it to have whatever you like.


Hi Network18,

You r correct..at that time it takes all types of files...k leave it...


I am having doubt on"upload_max_filesize" ..how can i change the values in php.ini file(which is located in server)...plz tell me is there any way to do by using coding????

i think this is stupid question, but no chance to me...


Thanks in advance..

sarithak
Junior Poster
183 posts since Aug 2008
Reputation Points: 10
Solved Threads: 7
 

Hi Network18,

You r correct..at that time it takes all types of files...k leave it...

I am having doubt on "upload_max_filesize" ..how can i change the values in php.ini file(which is located in server)...plz tell me is there any way to do by using coding????

i think this is stupid question, but no chance to me...

Thanks in advance..


Yes, you can do that by function ini_set()-

//This is your new size
$new_size = '3M';
ini_set('upload_max_filesize',$new_size);

most of the properties in the php.ini can be set during runtime using ini_set() function.The new values last there till the script executes.
And don't worry, nothing is stupid, until you don't know it:)
its always good to clarify the doubts here.

network18
Practically a Master Poster
619 posts since Sep 2009
Reputation Points: 29
Solved Threads: 76
 

Yes, you can do that by function ini_set()-

//This is your new size
$new_size = '3M';
ini_set('upload_max_filesize',$new_size);

most of the properties in the php.ini can be set during runtime using ini_set() function.The new values last there till the script executes. And don't worry, nothing is stupid, until you don't know it:) its always good to clarify the doubts here.


Hey...

Thanks to all....once again thanks a lot...keep it up...

sarithak
Junior Poster
183 posts since Aug 2008
Reputation Points: 10
Solved Threads: 7
 

hi sir,

This time i m getting warning

PHP Warning: POST Content-Length of 9484737 bytes exceeds the limit of 8388608 bytes in Unknown on line 0

i fixed the

$new_size = '20M';

ini_set('upload_max_filesize',$new_size);

the uploading file size is 9 to 10 MB...

sarithak
Junior Poster
183 posts since Aug 2008
Reputation Points: 10
Solved Threads: 7
 

hi sir,

This time i m getting warning

i fixed the

$new_size = '20M';

ini_set('upload_max_filesize',$new_size);

the uploading file size is 9 to 10 MB...


Does it solve your problem..you can supress any warning with prefixing '@' to the function like @ini_set(), eventhough i never recommend doing that.

network18
Practically a Master Poster
619 posts since Sep 2009
Reputation Points: 29
Solved Threads: 76
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You