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
C_Calav
Forum Contributor
Posts: 395 Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand
Post
by C_Calav » Mon Jun 28, 2004 12:07 am
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.
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Mon Jun 28, 2004 12:14 am
Try changing ($_FILES['file']['size'] > 1000)) to :
($_FILES['file']['size'] < 5000))
C_Calav
Forum Contributor
Posts: 395 Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand
Post
by C_Calav » Mon Jun 28, 2004 12:20 am
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?
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Mon Jun 28, 2004 12:22 am
Do a var_dump($_FILES);
What does that output?
C_Calav
Forum Contributor
Posts: 395 Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand
Post
by C_Calav » Mon Jun 28, 2004 12:30 am
how do i do that?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Jun 28, 2004 12:39 am
[php_man]var_dump[/php_man]
C_Calav
Forum Contributor
Posts: 395 Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand
Post
by C_Calav » Mon Jun 28, 2004 12:44 am
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) } }
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Mon Jun 28, 2004 12:48 am
Well image/pjpeg isn't a gif, and the code is checking for image/gif
C_Calav
Forum Contributor
Posts: 395 Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand
Post
by C_Calav » Mon Jun 28, 2004 12:49 am
thanx very much!
C_Calav
Forum Contributor
Posts: 395 Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand
Post
by C_Calav » Mon Jun 28, 2004 12:49 am
can i change it to take all type of images?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Jun 28, 2004 12:50 am
use [php_man]getimagesize[/php_man]() then..
C_Calav
Forum Contributor
Posts: 395 Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand
Post
by C_Calav » Mon Jun 28, 2004 1:03 am
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!
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Mon Jun 28, 2004 1:07 am
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) ?
C_Calav
Forum Contributor
Posts: 395 Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand
Post
by C_Calav » Mon Jun 28, 2004 1:11 am
everything exists. wha does this error have to do with? is it where my uploads folder is on the site?
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Mon Jun 28, 2004 1:20 am
is it where my uploads folder is on the site?
Yes.