...

View Full Version : File Uploads



pspsully
07-18-2007, 11:18 AM
Hi,

I have a flash music player on my comapny intranet that plays files form a folder called "mp3".

To allow employees upload their own music to this folder i created a form for them to do this:


<form action="main.php" enctype="multipart/form-data" method="POST">
<font class="style1">Add Music </font><input type="hidden" name="MAX_FILE_SIZE" value="9000000"><input type="file" name="userfile" id="userfile"><br><input type="submit" name="button" value="Submit"></form>


Now, to manage this i have the following code when submitted:



$uploadDir = 'mp3/';

if ($userfile != ''){
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];

// the files will be saved in filePath
$filePath = $uploadDir . $fileName;

// move the files to the specified directory
// if the upload directory is not writable or
// something else went wrong $result will be false
$result = move_uploaded_file($tmpName, $filePath);

}

Now, my problem is, when i upload an .mp3 file, it doesnt work but if i upload any other file, it does. I can upload .wma files aand they work fine just not mp3!!

Any ideas??

mlseim
07-18-2007, 01:58 PM
Your script does nothing with the Maximum size variable, but
your webhost might ... I'm thinking your webhost has limited the
maximum file size and you're seeing a situation where your MP3 file
is larger than they allow, yet the other files you upload were within
the limits.

Ask your webhost what the maximum filesize is set to.
Have them enlarge the default value to 10meg (or something like that).

pspsully
07-19-2007, 08:00 AM
Thanks for the reply,

but that aint where my problem lies!! Im not using a webhost, this is on a local machine in the office that has a webserver installed on it (Apache, PHP, MySQL etc.) And i can upload any other files that are bigger than mp3s but it just wont upload mp3s!!

Thanks again,

Sully

_Aerospace_Eng_
07-19-2007, 08:10 AM
echo $filePath to see if its where you are wanting the mp3s to go.

SMGames
07-19-2007, 08:54 AM
This is the code i have used to upload files:



<?php
if (($_FILES["file"]["type"] == "image/gif")


&& ($_FILES["file"]["size"] < 20000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
if (file_exists("mp3/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"mp3/" . $_FILES["file"]["name"]);
echo "You have successfully uploaded ". $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
But obviously you will change "image/gif" to whatever the mp3 file is, this works fine for me.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum