473,402 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Check $photo size and extension not working

Ok, here's my code. Can't get it to check file extension properly or file
size...had it working before but not sure why it's buggy now.

} elseif ($photo) {

$ext = strtolower(substr($photo, -3));

if ($ext == "peg") { $ext = "jpg"; }

if ($ext != "gif" || $ext != "jpg" || $ext != "jpeg" || $ext !="bmp" )
{

$focus = "photo";
$msg = "Please provide a valid gif, jpeg, or bmp photo";

} else {

$photo_size = getimagesize($photo);

if ($photo_size > 25000) {

$msg = "Photo must be smaller than 25k.";

}}} elseif { etc, etc. } else { dbqueries...
Jul 17 '05 #1
5 2581
Philip D Heady wrote:

Ok, here's my code. Can't get it to check file extension properly or file
size...had it working before but not sure why it's buggy now.

} elseif ($photo) {

$ext = strtolower(substr($photo, -3));

if ($ext == "peg") { $ext = "jpg"; }

if ($ext != "gif" || $ext != "jpg" || $ext != "jpeg" || $ext !="bmp" )
{

$focus = "photo";
$msg = "Please provide a valid gif, jpeg, or bmp photo";

} else {

$photo_size = getimagesize($photo);

if ($photo_size > 25000) {

$msg = "Photo must be smaller than 25k.";

}}} elseif { etc, etc. } else { dbqueries...


This is likely your problem:

if ($ext != "gif" || $ext != "jpg" || $ext != "jpeg" || $ext !="bmp" )

This line will always return true. You want to change the ORs to ANDs.

Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #2
Shawn Wilson <sh***@glassgiant.com> wrote in message news:<40***************@glassgiant.com>...

This is likely your problem:

if ($ext != "gif" || $ext != "jpg" || $ext != "jpeg" || $ext !="bmp" )

This line will always return true. You want to change the ORs to ANDs.

Shawn


if $ext does not equal gif jpg jpeg or bmp then display message
"Please provide a valid gif, jpeg, or bmp photo"

when i attach any of those file type extensions it does not bypass
that message, still asks me to provide a valid gif, etc..

Philip D. Heady
http://www.ignission.com
Jul 17 '05 #3
Philip D Heady wrote:

Shawn Wilson <sh***@glassgiant.com> wrote in message news:<40***************@glassgiant.com>...

This is likely your problem:

if ($ext != "gif" || $ext != "jpg" || $ext != "jpeg" || $ext !="bmp" )

This line will always return true. You want to change the ORs to ANDs.

Shawn


if $ext does not equal gif jpg jpeg or bmp then display message
"Please provide a valid gif, jpeg, or bmp photo"

when i attach any of those file type extensions it does not bypass
that message, still asks me to provide a valid gif, etc..


Say you have a file, image.jpg. Look at the first part of your if statement.
$ext is "jpg". So you're saying:

if ("jpg" != "gif" OR blah blah blah)
write error statement;

And "jpg" is not the same as "gif", and with OR statements, only one part needs
to be true for the whole thing to be true, so it writes the error.

You want:

if ($ext != "gif" && $ext != "jpg" && $ext != "jpeg" && $ext !="bmp" )
write error statment;

Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #4
Tried && approach, didn't work. What gives?
} elseif ($password != $password2) {
$focus = "password2";
$msg = "Passwords do not match.";

} elseif ($photo) {

$ext = strtolower(substr($photo_name, -3));

if ($ext == "peg") { $ext = "jpg";

} if ($ext != "gif" && $ext != "jpg" && $ext != "jpeg" && $ext
!="bmp" ) {

$focus = "photo";
$msg2 = "Please provide a valid gif, jpeg, or bmp photo";

} else {
$photo_size = getimagesize($photo);

if ($photo_size > 25000) {

$msg2 = "Photo must be smaller than 25k.";

}}} elseif ($username) {

$q = "SELECT id FROM account WHERE username='". apos($username) ."'";
$res = mysql_query($q);
$num = mysql_num_rows($res);

if ($num > 0) {
$focus = "username";
$msg = "This username is taken, please choose a different one.";

}} else {

$q = "INSERT INTO account (";
Jul 17 '05 #5
Philip D Heady wrote:

Tried && approach, didn't work. What gives?

} elseif ($password != $password2) {
$focus = "password2";
$msg = "Passwords do not match.";

} elseif ($photo) {

$ext = strtolower(substr($photo_name, -3));

if ($ext == "peg") { $ext = "jpg";

} if ($ext != "gif" && $ext != "jpg" && $ext != "jpeg" && $ext
!="bmp" ) {

$focus = "photo";
$msg2 = "Please provide a valid gif, jpeg, or bmp photo";

} else {

$photo_size = getimagesize($photo);

if ($photo_size > 25000) {

$msg2 = "Photo must be smaller than 25k.";

}}} elseif ($username) {

$q = "SELECT id FROM account WHERE username='". apos($username) ."'";
$res = mysql_query($q);
$num = mysql_num_rows($res);

if ($num > 0) {
$focus = "username";
$msg = "This username is taken, please choose a different one.";

}} else {

$q = "INSERT INTO account (";


You mean you're still getting the same error message? If so, print out the
extension and name:

$msg2 = "Please provide a valid gif, jpeg, or bmp photo. Extension: $ext . Name:
$photo_name";

That should give you an idea why it's not matching. My guess is $photo_name is
not what you think it is. If so, try the $_FILES['filename']['name'] format.

And you might want to go with a regex for the IF statement. It's a bit
cleaner. I'm not sure if it'd be faster or not.

if (!preg_match("/(gif|jpeg|jpg|bmp)$/", $foo)) //<--UNTESTED

Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: tgundeck | last post by:
Does anyone know how I can check the file size of photos or any file type in JavaScript? I'm allowing users to store photos in my web page using the input type = file tag, but need to limit the...
1
by: Bill Strass | last post by:
I have a form showing the records of different people. I would like a photo to be displayed in the form, with each person's record. My digital photo > *.jpg type file and I change each photo...
2
by: RC | last post by:
I want to display photos and when the user clicks on one the photo gets displayed in its own window. This is what I"m currently using. <A id="picAnchor" target="_blank"...
1
by: Kenny | last post by:
The following link will take you to menu of photo galleries. If you open any of the photo galleries you will see that each contains thumbnails. When a thumbnail is clicked, the full-sized version...
1
by: desjardins.daniel | last post by:
Hi ! Excuse my english, i'm a french canadien... So here my message : I have put on my site a photo gallery and at the right a nav menu. This menu has a red dot visible want someone is passing...
13
by: Viken Karaguesian | last post by:
Hello everyone, Can anyone recommend a good online site to learn PHP? The W3Schools website is quite lacking - leaves much to be desired. I'm sure there are many places, but which ones are good?...
3
by: boyet59 | last post by:
VerosMedia.com offers professional, digital retouching and photo restoration services. ** Restoration of treasured, family photographs. ** Portrait and model portfolio retouching. ** Photo...
1
by: SPE - Stani's Python Editor | last post by:
Phatch is a simple to use cross-platform GUI Photo Batch Processor Phatch handles all popular image formats and can duplicate (sub)folder hierarchies. It can batch resize, rotate, apply...
1
by: nwclark | last post by:
I am a noobie so pleas bear with me.. I am trying to link a image to a MYSQL variable. I have user photos that i would like to link this page. So far I created an image upload and renamed the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.