Jump to content

Archived

This topic is now archived and is closed to further replies.

RTS

PHP upload script wont upload mp3's

Recommended Posts

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]<?php

if(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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
If that's the script you're using, the mp3 files would end up in the /image folder not /music.

Share this post


Link to post
Share on other sites
What is your upload_max_filesize in phpinfo? (The default is 2 mb)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 helps
music.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]

Share this post


Link to post
Share on other sites
[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 helps
music.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...

Share this post


Link to post
Share on other sites
so heres my upload.php script which processes the form data [code=php:0]<?php
set_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.

Share this post


Link to post
Share on other sites
Oh.  I know nothing about about apache 1.3, much less on mac... Hmmm...

Share this post


Link to post
Share on other sites
[code]
<?php

ini_set('upload_max_filesize', '10MB');

?>
[/code]

Try that.  You need to place both values within the boundaries of quotation marks.

Share this post


Link to post
Share on other sites
hmm I dont get the error anymore, but the file still doesnt upload

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
After you make a change to your php.ini you have to restart your web server. This should work for you.

Share this post


Link to post
Share on other sites
okay, I just had to restart apache, thanks  :)

Share this post


Link to post
Share on other sites
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'>
<?php
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]
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 82

Warning: 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?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.