...

View Full Version : Resolved Upload script questions



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">&nbsp;
<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";
}
?>

karlosio
12-11-2008, 04:56 AM
Depends on how big the mp3 file is, PHP has 16MB set as default for file uploads, you may need to change this in the PHP.INI file. First check out by running phpinfo(). Open a new php file and enter this:


<?php phpinfo(); ?>

What you need to looks for and possibly change is:

post_max_size (16MB by default) make this slightly higher than upload_max_filesize so it can submit the form info, if required.
upload_max_filesize (also 16MB by default)
max_execution_time (60 seconds by default, might need to make this higher to stop timing out errors)

Jedi Knight
12-11-2008, 05:31 AM
My 'upload max filesize' 24MB
My 'post max size' 32MB
But my 'max execution time' is only 60

I don't think I have access to change this.
I'll have to get with my host and see if I can get it changed.
But that probable is my problem, as I'm on a slow connection when it comes to uploading.

Thanks for your great help.
Do you have any ideas about the second problem I mentioned above?


After doing some reading, I am wondering if an alternate course may be taken.
Instead of trying to get my php.ini file edited (not very likely), can the 'max execution time' by altered with .htaccess, or this code:


<? ini_set("session.gc_maxexecutiontime","180"); ?>

Jedi Knight
12-11-2008, 02:22 PM
I'm beginning to think it is not a timeout problem.
I just converted a mp3 file down to 413KB and it still won't upload it.
I've uploaded larger image files than 413KB.
So it must be the mime type.

Does anyone see anything wrong with the code above.
Particularly this part:


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


Should

|| ($_FILES["file"]["type"] == "audio/mpeg3")


Be this instead

|| ($_FILES["file"]["type"] == "audio/mp3")


I finally got it to work by adding the following:


|| ($_FILES["file"]["type"] == "audio/mpeg")
|| ($_FILES["file"]["type"] == "audio/x-mpeg")
|| ($_FILES["file"]["type"] == "aaudio/mp3")
|| ($_FILES["file"]["type"] == "audio/x-mp3")
|| ($_FILES["file"]["type"] == "audio/mpeg3")
|| ($_FILES["file"]["type"] == "audio/mpg")
|| ($_FILES["file"]["type"] == "audio/x-mpg")
|| ($_FILES["file"]["type"] == "audio/x-mpegaudio")


I'm sure that this may be redundant, but not knowing which one is correct, I'll just leave all of them in there.

Now if I can get the link to display correctly, I can mark this thread as solved.
Would str_replace fix this, and if so, can someone post an example?

Jedi Knight
12-11-2008, 10:49 PM
I used urlencode and urldecode and got it working the way I want it. Thanks for helping.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum