[SOLVED] help with uploading script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

[SOLVED] help with uploading script

Post 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.';
}
?>
Last edited by C_Calav on Mon Jun 28, 2004 12:21 am, edited 2 times in total.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Try changing ($_FILES['file']['size'] > 1000)) to :
($_FILES['file']['size'] < 5000))
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post 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?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Do a var_dump($_FILES);
What does that output?
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

how do i do that?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

[php_man]var_dump[/php_man]
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post 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) } }
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Well image/pjpeg isn't a gif, and the code is checking for image/gif :o
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

thanx very much!
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

can i change it to take all type of images?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

use [php_man]getimagesize[/php_man]() then..
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post 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!
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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) ?
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

everything exists. wha does this error have to do with? is it where my uploads folder is on the site?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

is it where my uploads folder is on the site?
Yes.
Post Reply