Page 1 of 2

[SOLVED] help with uploading script

Posted: Mon Jun 28, 2004 12:07 am
by C_Calav
hey guys, i have got this script off a tutorial but it keeps saying
"Sorry, we only accept .gif images under 5Kb for upload" no matter what i do to change the code to that problem eg, make file size bigger/smaller etc.

can anyone help or recomend anything else?

thanx!

Code: Select all

<?php
if (($_FILES['file']['type'] == 'image/gif') &&
($_FILES['file']['size'] < 5000))
{
echo 'Return Code: ' . $_FILES['file']['error'] . '<br />';
echo 'Uploading ' . $_FILES['file']['name'] . ' (' .
$_FILES['file']['type'] . ', ' .
ceil($_FILES['file']['size'] / 91024) . ' Kb).<br />';

if (file_exists('uploads/' . $_FILES['file']['name']))
{
echo $_FILES['file']['name'] . ' already exists. ';
echo 'Please delete the destination file and try again.';
}

else
{
move_uploaded_file($_FILES['file']['tmp_name'],
'uploads/' . $_FILES['file']['name']);
echo 'File has been stored in your uploads directory.';
}

} 

else
{
echo 'Sorry, we only accept .gif images under 5Kb for upload.';
}
?>

Posted: Mon Jun 28, 2004 12:14 am
by markl999
Try changing ($_FILES['file']['size'] > 1000)) to :
($_FILES['file']['size'] < 5000))

Posted: Mon Jun 28, 2004 12:20 am
by C_Calav
sorry thats what it was ment to be in the first place! i hadnt changed it back, ill just edit this post. thanx for pointing that out.

any idea's why it wont work?

Posted: Mon Jun 28, 2004 12:22 am
by markl999
Do a var_dump($_FILES);
What does that output?

Posted: Mon Jun 28, 2004 12:30 am
by C_Calav
how do i do that?

Posted: Mon Jun 28, 2004 12:39 am
by feyd
[php_man]var_dump[/php_man]

Posted: Mon Jun 28, 2004 12:44 am
by C_Calav
thanx,

it gave me

for upload.array(1) { ["file"]=> array(5) { ["name"]=> string(7) "aaa.gif" ["type"]=> string(11) "image/pjpeg" ["tmp_name"]=> string(14) "/tmp/phpWtfPnQ" ["error"]=> int(0) ["size"]=> int(3765) } }

Posted: Mon Jun 28, 2004 12:48 am
by markl999
Well image/pjpeg isn't a gif, and the code is checking for image/gif :o

Posted: Mon Jun 28, 2004 12:49 am
by C_Calav
thanx very much!

Posted: Mon Jun 28, 2004 12:49 am
by C_Calav
can i change it to take all type of images?

Posted: Mon Jun 28, 2004 12:50 am
by feyd
use [php_man]getimagesize[/php_man]() then..

Posted: Mon Jun 28, 2004 1:03 am
by C_Calav
took out the valadation for type and it works.. well.. kinda.

Return Code: 0
Uploading Plane.jpg (image/pjpeg, 1 Kb).

Warning: move_uploaded_file(uploads/Plane.jpg): failed to open stream: No such file or directory in /var/users/modelair/modelaircraft.co.nz/htdocs/admin/upload.php on line 18

Warning: move_uploaded_file(): Unable to move '/tmp/phpKfgNkJ' to 'uploads/Plane.jpg' in /var/users/modelair/modelaircraft.co.nz/htdocs/admin/upload.php on line 18
File has been stored in your uploads directory.

getting these erros but no picture in my uploads directory!

Posted: Mon Jun 28, 2004 1:07 am
by markl999
And does /var/users/modelair/modelaircraft.co.nz/htdocs/admin/uploads exists and is it writeable by the webserver user (apache, nobody, www-data, whoever) ?

Posted: Mon Jun 28, 2004 1:11 am
by C_Calav
everything exists. wha does this error have to do with? is it where my uploads folder is on the site?

Posted: Mon Jun 28, 2004 1:20 am
by markl999
is it where my uploads folder is on the site?
Yes.