Page 1 of 1

[solved] php upload: gifs works, jpg fails

Posted: Sun Nov 28, 2004 11:00 am
by GhostXL
Using this this code to upload pictures to my site gif images work fine but with jpeg images the $userfile doesn't get a value so the script fails.

HTML form ("action=upload.php" == the script below)
<body>
<form enctype="multipart/form-data" method="post" action="upload.php">
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="20000">
<p>
Bestand:
<input type="file" name="userfile">
</p>
<p>
Doelmap:
<input type="text" name="doelmap">
</p>
<p>
Betandsnaam:
<input type="text" name="bestandsnaam">
</p>
<p>
<input type="submit" name="Submit" value="uploaden">
</p>
</form>
</body>

Code: Select all

<?php
if (file_exists($doelmap."/".$bestandsnaam)==true){
echo "bestand ".$doelmap."/".$bestandsnaam." bestaat al<br>";
if (unlink($doelmap."/".$bestandsnaam)==1){
echo "oud bestand verwijderd<br>";
} else {
echo "er is een fout opgetreden bij het verwijderen bestand <br>";
}
} else {
echo "bestand ".$doelmap."/".$bestandsnaam." bestaat nog niet<br>";
}
?>
<p>&nbsp;</p>
<?php
if (rename($userfile,$doelmap."/".$bestandsnaam)==true){
echo "Bestand is met succes geupload<br>";
} else {
echo "Er is een fout opgetreden bij het uploaden van het bestand<br>";
}
?>
By the way, using php 4.2.2

Posted: Sun Nov 28, 2004 11:25 am
by timvw
is it possible to show concrecte code where it goes wrong? because now we can't see where the $userfile is coming from...

Posted: Sun Nov 28, 2004 1:07 pm
by GhostXL
The variables are coming from a form (see above (edited the post)).
The php-script above is the upload.php used in de action artibute of the form.

Posted: Sun Nov 28, 2004 3:14 pm
by John Cartwright
your code requires register globals to be on.

$userfile should be renamed to $_POST['userfile']

Posted: Sun Nov 28, 2004 4:36 pm
by GhostXL
So why do gif images upload correctly, $userfile has a value then....
So has nothing to do with globals, or i'm i missing something?

OMG I'm a NOOB.............
Have a filezise limit of only 20000 bytes :?

Dude there's nothing wrong with da script, its just me.
I removed the
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="20000">
from the form, and done....