Jump to content

PHP upload script wont upload mp3's


RTS

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]
Link to comment
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]
Link to comment
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...
Link to comment
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.
Link to comment
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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.