PDA

View Full Version : upload mp3s


Guy
10-21-07, 01:23 PM
I'm am currently starting to work on a cms for a client, the client needs to be able to upload MP3 files to a folder and add nodes to a xml file for this to work correctly, Im starting this with the upload.

The coding below if what I currently have:
This is the standard HTML
<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>

This is the PHP
<?php

if (($_FILES["file"]["type"] == "audio/mpeg")
||($_FILES["file"]["type"]=="audio/x-mpeg")
||($_FILES["file"]["type"]=="audio/x-mpeg-3")
||($_FILES["files"]["type"]=="audio/mpeg3")

)
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1000024) . " M<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

if (file_exists("tracks/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"tracks/" . $_FILES["file"]["name"]);
echo "Stored in: " . "tracks/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file <br />";

}
?>

This all works fine as long as the mp3 is at a bit rate below 100, (it will upload any mp3 with a bit rate of 32 64 96 ect..)
but if I try to upload a mp3 with a bit rate of 128 I get the Invalid File echo.
Is there another mime type that I have not included??
or is there something that I need to configure in the PHP.ini file

I am working with these locally (on my computer) until I get it work correctly
these are the current setting on my php.ini
the largest file I have tried to upload with this code is 4.5 m

file_uploads = On
upload_tmp_dir = "C:\Program Files\xampp\tmp"
upload_max_filesize = 32M

Thanks in advance

HalfaBee
10-21-07, 04:22 PM
have you tried doing a print_r( $_FILES ) to see it the type is set to something else?

You will need to set the upload_tmp_dir to a valid dir in your webspace.
Files will also have to be chmod 644 after moving, as it is set to 600 by default.

There is also a 15 min timeout, so large files over a slow network can timeout.

Guy
10-21-07, 07:57 PM
I tried that this is what I get with a mp3 at bit rate of 128
Array ( [file] => Array ( [name] => Dancing_in_the_Streets2.mp3 [type] => [tmp_name] => [error] => 1 [size] => 0 ) )

this is what I get with a mp3 at bit rate of 96 or lower
Array ( [file] => Array ( [name] => 478133_SOUNDDOGS_Me.mp3 [type] => audio/mpeg [tmp_name] => C:\DOCUME~1\???\LOCALS~1\Temp\php\upload\phpFD.tmp [error] => 0 [size] => 1923388 ) )

I guess I need to find out what error 1 is

You will need to set the upload_tmp_dir to a valid dir in your webspace.
Files will also have to be chmod 644 after moving, as it is set to 600 by default.

I am currently doing this on my local apache/php server so the upload_tmp_dir is a valid dir, if I understand what you are saying. But I'm not sure about chmod to 644 whats up with that?

HalfaBee
10-21-07, 08:17 PM
That is for a unix based webhost, assuming you are going to host this at Powweb. ;)

the manual is your friend ;)
http://www.php.net/manual/en/features.file-upload.errors.php

Guy
10-21-07, 08:38 PM
That is for a unix based webhost, assuming you are going to host this at Powweb.

yes thats what I thought you meant, right now Im testing it on a window system ...
any Idea on what error 1 is ??
I have been looking around the web but havent come up with anything yet

Guy
10-21-07, 08:50 PM
I looked at the link "the manual is your friend"

"UPLOAD_ERR_INI_SIZE

Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini. "

If error 1 = file exceeds the upload_max_filesize directive in php.ini.

Im more Confused now that when I started looking this up
upload_max_filesize in my php.ini = 32m's
the file is only 4.5m's
Maybe its time to hit the books to make some sanity out of this one

HalfaBee
10-21-07, 09:06 PM
You can try putting this in the form
<input type="hidden" name="MAX_FILE_SIZE" value="32000000" />

before the file input box.

Guy
10-21-07, 09:15 PM
yes I tried that also with
<input type="hidden" name="MAX_FILE_SIZE" value="30000000" />

but it still come back saying Invalid file

so I went and created a mp3 with the bit rate of 128 but had no data in it so it was really small, it uploaded it .... so I guess its not the bit rate but the size of the file, does PHP have a time limit on uploads?? and if so can I change it in PHP.ini

HalfaBee
10-21-07, 09:39 PM
It could be an apache setting that needs changing.

Guy
10-21-07, 10:00 PM
I didn't think of that, Ill start looking

Guy
10-21-07, 10:17 PM
that was it:p

I figured instead of checking my apache settings I would check powwebs, Its going to be here when its done and changing my setting would do no good if powwebs settings are set for a upload like this. So I ftped it all up and checked it , it loaded. It took about 20-30 seconds but it works.

Now I just have to figure out the xml stuff, another day

HalfaBee--
thanks for the help