Re: Pictureupload
| From: | Richard Davey | Date: | Thu, 03 Nov 2005 17:00:41 +0000 |
| Subject: | Re: Pictureupload | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-225059@lists.php.net to get a copy of this message | ||
Hi twistednetadmin,
Thursday, November 3, 2005, 4:50:33 PM, you wrote:
> I have made this script to upload pictures into a picturegallery on a
> website.
> The script works just as I expected, but with one huge flaw. It doesn't work
> from every users computer.
> I can upload pictures with no problem, but another user get's an
> errormessage. the other user emailed the picture to me and I could upload it
> with no errors.
> Here's the script.
> <form name="guildimage_upload" method="post" action="<?php
> $_SERVER['PHP_SELF'] ?>" enctype="multipart/form-data">
> <table class="normal" border="0" align="center">
> <tr>
> <td height="200" align="center" valign="bottom"
> class="holyheader18">Screenshot upload</td></tr>
> <tr>
> <td align="center" colspan="2">
> <table border="1">
> <tr>
> <td>
> Only pictures with the .jpg extension and size 300kb or less will be
> uploaded!<br>
> Imagenames should not contain quotes or any special signs!!<br>
> </td>
> </tr>
> </table>
> </td>
> </tr>
> <tr>
> <td>
> File:
> <input type="hidden" name="MAX_FILE_SIZE" value="300000">
> <input type="file" name="guildimage">
> </td>
> </tr>
> <tr>
> <td>
> Comment:
> <input name="guildimage_comment" type="text" size="40"
> maxlength="40">
> </td>
> <td>
> <input type="submit" name="submit" value="Summon">
> </td>
> </tr>
> </tr>
> <tr>
> <td height="160" colspan="2" class="maintext"
> valign="top">
> <?php
> chmod("/guildimages/", 0777);
> ######################################################
> ###Uploads the image and checks if the image exists already###
> ######################################################
> if (isset($_POST['submit'])) //If you push the submit-button
> {
> $sysfolder="/guildimages/";
> $filename="".$_FILES['guildimage']['name']."";
> if (file_exists($sysfolder . $filename)) //If the filename exists.
> {
> echo "Filename exists or no file selected. Please rename the file or select
> a file";
> }
> elseif ($_FILES['guildimage']['type'] == "image/jpeg") //And if
> the image
> is .jpg less or equal 300kb...
> {
> copy ($_FILES['guildimage']['tmp_name'],
> "/guildimages/".$_FILES['guildimage']['name']) //Copy the image
> to
> /guildimages
> or die("Could not copy file"); //Or don't if it's wrong size or format
> $insertSQL = sprintf("INSERT INTO guildimages (guildimage_date,
> guildimage_name, guildimage_comment, posted_by) VALUES (NOW(), '%s', '%s',
> '%s')",
> ($_FILES['guildimage']['name']),
> ($_POST['guildimage_comment']),
> ($_SESSION['logname']));
> $guildimage_upload = mysql_query($insertSQL) or die(mysql_error());
> //insert all info to the DB
> echo "Result:<br>\n";
> echo "Filename:
> ".$_FILES['guildimage']['name']."<br>\n";
> echo "Filesize: ".$_FILES['guildimage']['size']."
> byte<br>\n";
> echo "Filtype:
> ".$_FILES['guildimage']['type']."<br>\n";
> echo "Congrats! It worked!\n";
> }
> else
> {
> echo "Result:<br>\n";
> echo "Now that didn't seem to work... <br>\n
> Did you try a wrong format or size? <br>\n
File that failed-->>
(".$_FILES['guildimage']['name'].")<br>";
> }
> }
?>>
> </td>
> </tr>
> </table>
> </form>
> Can anyone see what's wrong? Since it works from some computers and not from
> all?
How large was the image? Could it be that the script is timing out
during an upload? I recently had to change the max_input_time value on
one site because the uploads were so large they kept timing the script
out, yet some people (on really fast connections) could upload just
fine.
Cheers,
Rich
--
Zend Certified Engineer
PHP Development Services
http://www.corephp.co.uk