Jump to content


Photo

PHP upload script wont upload mp3's


  • Please log in to reply
16 replies to this topic

#1 RTS

RTS
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 10 August 2006 - 11:57 PM

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
<?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); }
?>


#2 DillyDong

DillyDong
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 11 August 2006 - 12:42 AM

How exactly does it not work? What's the error message? Is the file size too large?

#3 RTS

RTS
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 11 August 2006 - 12:50 AM

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?

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 11 August 2006 - 01:44 AM

If that's the script you're using, the mp3 files would end up in the /image folder not /music.
Legend has it that reading the manual never killed anyone.
My site

#5 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 11 August 2006 - 01:46 AM

What is your upload_max_filesize in phpinfo? (The default is 2 mb)

#6 laide234

laide234
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 11 August 2006 - 01:50 AM

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.

#7 RTS

RTS
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 11 August 2006 - 05:03 AM

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:
<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'>


#8 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 11 August 2006 - 06:00 AM

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:

<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'>


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...
Why doesn't anyone ever say hi, hey, or whad up world?

#9 RTS

RTS
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 11 August 2006 - 05:34 PM

so heres my upload.php script which processes the form data
<?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); }
      ?>

it gave me
Parse error: parse error in /Library/WebServer/Documents/upload.php on line 2

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.

#10 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 11 August 2006 - 05:37 PM

Oh.  I know nothing about about apache 1.3, much less on mac... Hmmm...
Why doesn't anyone ever say hi, hey, or whad up world?

#11 mewhocorrupts

mewhocorrupts
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts
  • LocationParker, CO

Posted 11 August 2006 - 05:46 PM

<?php

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

?>

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

#12 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 11 August 2006 - 05:50 PM

Oh, dang dunno how i missed that... Hehe
Why doesn't anyone ever say hi, hey, or whad up world?

#13 RTS

RTS
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 11 August 2006 - 05:54 PM

hmm I dont get the error anymore, but the file still doesnt upload

#14 RTS

RTS
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 11 August 2006 - 06:10 PM

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?

#15 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 11 August 2006 - 08:15 PM

After you make a change to your php.ini you have to restart your web server. This should work for you.

#16 RTS

RTS
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 11 August 2006 - 08:35 PM

okay, I just had to restart apache, thanks  :)

#17 RTS

RTS
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 11 August 2006 - 08:57 PM

one more question, if I want my script to be contained in the same file in my form, I need something like this right?
<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); }
      ?> 
But When I have it as that I get
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
any ideas on how I can fix this?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users