Jedi Knight
12-11-2008, 04:04 AM
I've been playing around with this upload script.
It seems to work fine for the smaller img formats, but not for mp3 files.
I don't know if it's a file type or file size problem.
It appears to upload the mp3, but no link is given and the mp3 is not in the upload directory.
Edit: Or maybe it could be a timeout problem. I don't know.
And another thing I need fixing is the link display.
If you upload a file with spaces in the title, the link shows the spaces.
I need it to actually print the url to the file.
echo "Link: " . "http://mydomain.com/upload/files/" . $_FILES["file"]["name"];
Here is the script, if anyone can lend a hand.
<form action="upload.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br /><br />
<input type="submit" name="submit" onclick="showIcon();" value="Submit" /><br /><br />
<div class="progress" id="progressImg">
<img src="http://mydomain.com/upload/progress.gif" alt="Uploading" />
</div>
</form>
<br />
<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "audio/mpeg3")
|| ($_FILES["file"]["type"] == "application/x-shockwave-flash")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 10485760))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
if (file_exists("files/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"files/" . $_FILES["file"]["name"]);
echo "Link: " . "http://mydomain.com/upload/files/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
It seems to work fine for the smaller img formats, but not for mp3 files.
I don't know if it's a file type or file size problem.
It appears to upload the mp3, but no link is given and the mp3 is not in the upload directory.
Edit: Or maybe it could be a timeout problem. I don't know.
And another thing I need fixing is the link display.
If you upload a file with spaces in the title, the link shows the spaces.
I need it to actually print the url to the file.
echo "Link: " . "http://mydomain.com/upload/files/" . $_FILES["file"]["name"];
Here is the script, if anyone can lend a hand.
<form action="upload.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br /><br />
<input type="submit" name="submit" onclick="showIcon();" value="Submit" /><br /><br />
<div class="progress" id="progressImg">
<img src="http://mydomain.com/upload/progress.gif" alt="Uploading" />
</div>
</form>
<br />
<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "audio/mpeg3")
|| ($_FILES["file"]["type"] == "application/x-shockwave-flash")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 10485760))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
if (file_exists("files/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"files/" . $_FILES["file"]["name"]);
echo "Link: " . "http://mydomain.com/upload/files/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>