PDA

View Full Version : Image upload script problem !!


wap3
04-30-2003, 05:09 PM
Hi guys

I found a script whilst searching here for uploading an image.
I have modified the script abit to try and get it to work for my situation.

The script doesn't generate any errors and reaches it's destination so to speak, where it says "your submission has been . . "

And along the way it also echos out the statements I put in there for testing purposes, so I know it has picked up the post variables and has the right path to the image. But it just doesn't save the image to the folder named 'Images'.

Any ideas why ??


function check_image($HTTP_POST_VARS) {
echo "$HTTP_POST_VARS[image]";
$upload_error = '';
if(isset($HTTP_POST_VARS['image']['tmp_name']) && $HTTP_POST_VARS['image']['tmp_name'] !== "none")
{
$f_type = getimagesize($HTTP_POST_VARS['image']);
foreach($f_type as $key) {
echo "$key"; }
if($f_type[2] > 0)
{
// ftype[2] returns the filetype - where a valid image is always above zero
// you could type test further - maybe !== 2 ~ not jpeg or somesuch.
if($HTTP_POST_VARS['image']['size'] < 116000)
{
// check image size in bytes
$name = $HTTP_POST_VARS['image']['name'];
$upfile = "../Images/".$name;
copy($HTTP_POST_VARS['image'], $upfile);
echo 'Your submission has been saved and our administrator will check it shortly, thankyou.<br /><br />';
}
else
{
echo "The file you uploaded was not below 116kb.";
}
}
else
{
echo "The file you uploaded was not a valid image file.";
}
}
}


:thumbsup:

missing-score
04-30-2003, 06:10 PM
It could be because of the CHMOD of the directory. Ensure it is 777, or something similar.

wap3
04-30-2003, 06:16 PM
Hi missing score

thanks for replying. I am testing this script on my computer with phpdev.

So that shouldn't make a difference at this stage should it ??
:D

missing-score
04-30-2003, 07:05 PM
Right, it looks fine.

Ensure the directory ../Images/ exists.

Also, remember that ../ goes back a dir, so you are going to (likely) C:\phpdev5\Images\

Try adding a directory in C:\phpdev5\www\Images, and upload to there.

If that doesnt work, ensure that you have the right case ( Images is not images)

Add in some "if/else"'s and set error_reporting(E_ALL);

other than that, try uploading it to a server online, and (CHMOD) and see if it works there.


It looks fine... :confused:

wap3
04-30-2003, 07:44 PM
Ok I tried it again and it has the right directory and everything it seems there is a problem with what it is trying to save.

I noticed this time it is creating a little file called 'c' with no recognisable file extension.

So it seems it is not determining the file name from the input given.

I.e

when i ask it to echo "$HTTP_POST_VARS[image]"; it writes something like this to the screen:

C:\\Documents and Settings\\default\\My Documents\\Internet Downloads\\agents.gif

so the 'c' must be what it is trying to save and not the 'agents.gif' part.

Any ideas how to overcome that ??

:thumbsup:

missing-score
04-30-2003, 08:15 PM
uhhh, no to be honest.

I will have a look, but it seems like it should work fine.

Try uploading it to a remote server, see if it works on there.

Ökii
04-30-2003, 10:35 PM
try updating all your variable calls to use the

$_FILES array rather than $_POST_VARS

<html>
<body>
<?php
if($_POST['done'] == 'yes')
{
foreach($_FILES['upload_ref'] as $varname=>$varvalue)
{
echo '$_FILES[\\'upload_ref\\'][\\'' .$varname. '\\'] = ' .$varvalue. '<br />';
}
}
?>
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>" enctype="multipart/form-data">
<input type="hidden" name="done" value="yes" />
<input type="file" name="upload_ref" /><br />
<input type="submit" value="upload now" />
</form>
</body>
</html>

try running that and slinging any old file in - check the returns are ok and use those to address the uploaded file.