RTS Posted August 10, 2006 Share Posted August 10, 2006 In just finished a script to upload mp3 files to a folder called music on my server. the problem is, whenevern I try to upload an mp3 it doesnt work. I know the script somehow works, because I tried uploading a jpg and it uploaded perfectly. any ideas? heres my script btw [code]<?phpif(is_uploaded_file($_FILES['userfile']['tmp_name'])){ $uploadfile = str_replace("upload.php", "image/", $_SERVER['SCRIPT_FILENAME']) . str_replace(' ', '', strtolower(basename($_FILES['userfile']['name']))); move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile); }?> [/code] Quote Link to comment https://forums.phpfreaks.com/topic/17187-php-upload-script-wont-upload-mp3s/ Share on other sites More sharing options...
DillyDong Posted August 11, 2006 Share Posted August 11, 2006 How exactly does it not work? What's the error message? Is the file size too large? Quote Link to comment https://forums.phpfreaks.com/topic/17187-php-upload-script-wont-upload-mp3s/#findComment-72800 Share on other sites More sharing options...
RTS Posted August 11, 2006 Author Share Posted August 11, 2006 theres no error message which is the wierd thing, and no my file is not too big (arround 3 mb.) do you have any thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/17187-php-upload-script-wont-upload-mp3s/#findComment-72803 Share on other sites More sharing options...
AndyB Posted August 11, 2006 Share Posted August 11, 2006 If that's the script you're using, the mp3 files would end up in the /image folder not /music. Quote Link to comment https://forums.phpfreaks.com/topic/17187-php-upload-script-wont-upload-mp3s/#findComment-72818 Share on other sites More sharing options...
cmgmyr Posted August 11, 2006 Share Posted August 11, 2006 What is your upload_max_filesize in phpinfo? (The default is 2 mb) Quote Link to comment https://forums.phpfreaks.com/topic/17187-php-upload-script-wont-upload-mp3s/#findComment-72820 Share on other sites More sharing options...
laide234 Posted August 11, 2006 Share Posted August 11, 2006 try smaller files... just to eliminate the possibilty of it being a file size issue.create 'test.mp3' (from a blank text document or something) and upload it. if it uploads, you know what the problem is. Quote Link to comment https://forums.phpfreaks.com/topic/17187-php-upload-script-wont-upload-mp3s/#findComment-72822 Share on other sites More sharing options...
RTS Posted August 11, 2006 Author Share Posted August 11, 2006 the blank mp3 file worked, and for that matter, a 500 kb mp3 also worked. the thing is, my script allows more than that, and I dont know what the problem is. heres my upload form if that helpsmusic.php:[code]<form enctype='multipart/form-data' action='upload.php' method='post'><input type='hidden' name='MAX_FILE_SIZE' value='99999999999999999'><input name='userfile' type='file'><input type='submit' value='Upload'>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17187-php-upload-script-wont-upload-mp3s/#findComment-72858 Share on other sites More sharing options...
corbin Posted August 11, 2006 Share Posted August 11, 2006 [quote author=RTS link=topic=103788.msg413619#msg413619 date=1155272601]the blank mp3 file worked, and for that matter, a 500 kb mp3 also worked. the thing is, my script allows more than that, and I dont know what the problem is. heres my upload form if that helpsmusic.php:[code]<form enctype='multipart/form-data' action='upload.php' method='post'><input type='hidden' name='MAX_FILE_SIZE' value='99999999999999999'><input name='userfile' type='file'><input type='submit' value='Upload'>[/code][/quote]Forms are entirely 100% server side... I dont feel like googling at the moment but someone could even use some simple javascript code in their address bar to reset the MAX_FILE_VALUE so if you had it set to 1024 they could set it to 99999999... NEVER rely on anything client side...Whats causing it to bounce your uploads is most likely your php.ini file... Like someone earlier said the default max is 2MB and most songs are 3-4MB....try something like set_ini("upload_max_filesize", XMB);at the top of your script that processes the upload (replace X with a number :D)Or if you have access to your php.ini just change upload_max_filesize in there... Quote Link to comment https://forums.phpfreaks.com/topic/17187-php-upload-script-wont-upload-mp3s/#findComment-72872 Share on other sites More sharing options...
RTS Posted August 11, 2006 Author Share Posted August 11, 2006 so heres my upload.php script which processes the form data [code=php:0]<?phpset_ini("upload_max_filesize", 10MB);if(is_uploaded_file($_FILES['userfile']['tmp_name'])){ $uploadfile = str_replace("upload.php", "music/", $_SERVER['SCRIPT_FILENAME']) . str_replace(' ', '', strtolower(basename($_FILES['userfile']['name']))); move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile); } ?> [/code]it gave me[code]Parse error: parse error in /Library/WebServer/Documents/upload.php on line 2[/code]I searched for php.ini, and didnt find anything. does this have something to do with using a mac? I am using apache 1.3.33. Quote Link to comment https://forums.phpfreaks.com/topic/17187-php-upload-script-wont-upload-mp3s/#findComment-73215 Share on other sites More sharing options...
corbin Posted August 11, 2006 Share Posted August 11, 2006 Oh. I know nothing about about apache 1.3, much less on mac... Hmmm... Quote Link to comment https://forums.phpfreaks.com/topic/17187-php-upload-script-wont-upload-mp3s/#findComment-73217 Share on other sites More sharing options...
mewhocorrupts Posted August 11, 2006 Share Posted August 11, 2006 [code]<?phpini_set('upload_max_filesize', '10MB');?>[/code]Try that. You need to place both values within the boundaries of quotation marks. Quote Link to comment https://forums.phpfreaks.com/topic/17187-php-upload-script-wont-upload-mp3s/#findComment-73229 Share on other sites More sharing options...
corbin Posted August 11, 2006 Share Posted August 11, 2006 Oh, dang dunno how i missed that... Hehe Quote Link to comment https://forums.phpfreaks.com/topic/17187-php-upload-script-wont-upload-mp3s/#findComment-73234 Share on other sites More sharing options...
RTS Posted August 11, 2006 Author Share Posted August 11, 2006 hmm I dont get the error anymore, but the file still doesnt upload Quote Link to comment https://forums.phpfreaks.com/topic/17187-php-upload-script-wont-upload-mp3s/#findComment-73241 Share on other sites More sharing options...
RTS Posted August 11, 2006 Author Share Posted August 11, 2006 okay, I found my php.ini file, which was actually called php.ini.default, in /private/etc and I updated it to be 10MB. It still isnt uploading though. did I change it correctly? What could be wrong? Quote Link to comment https://forums.phpfreaks.com/topic/17187-php-upload-script-wont-upload-mp3s/#findComment-73254 Share on other sites More sharing options...
cmgmyr Posted August 11, 2006 Share Posted August 11, 2006 After you make a change to your php.ini you have to restart your web server. This should work for you. Quote Link to comment https://forums.phpfreaks.com/topic/17187-php-upload-script-wont-upload-mp3s/#findComment-73314 Share on other sites More sharing options...
RTS Posted August 11, 2006 Author Share Posted August 11, 2006 okay, I just had to restart apache, thanks :) Quote Link to comment https://forums.phpfreaks.com/topic/17187-php-upload-script-wont-upload-mp3s/#findComment-73323 Share on other sites More sharing options...
RTS Posted August 11, 2006 Author Share Posted August 11, 2006 one more question, if I want my script to be contained in the same file in my form, I need something like this right?[code=php:0]<form enctype='multipart/form-data' action="<?php echo $_SERVER['PHP_SELF']; ?>" method='post'><input name='userfile' type='file'><input type='submit' value='Upload'><?phpif(is_uploaded_file($_FILES['userfile']['tmp_name'])){ $uploadfile = str_replace("upload.php", "music/", $_SERVER['SCRIPT_FILENAME']) . str_replace(' ', '', strtolower(basename($_FILES['userfile']['name']))); move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile); } ?> [/code]But When I have it as that I get[code]Warning: move_uploaded_file(/Library/WebServer/Documents/music.php09bloodhound.mp3): failed to open stream: Permission denied in /Library/WebServer/Documents/music.php on line 82Warning: move_uploaded_file(): Unable to move '/var/tmp/phpt5S5Zf' to '/Library/WebServer/Documents/music.php09bloodhound.mp3' in /Library/WebServer/Documents/music.php on line 82[/code] any ideas on how I can fix this? Quote Link to comment https://forums.phpfreaks.com/topic/17187-php-upload-script-wont-upload-mp3s/#findComment-73329 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.