Jump to content

being redirected everytime


garydt

Recommended Posts

When the user uploads an image the script checks to see if its a jpeg. If it isn't it will redirect to another page but its redirecting regardless of the image being a jpeg or not.


$chktype = $_FILES['file']['type'];
if ($chktype!='jpeg' or $chktype!='JPEG') {
     header("Location: regform2.php");
 exit;
}

Link to comment
Share on other sites

 

You can also use the function getimagesize()

 

Example:

list($width, $height, $type, $attr) = getimagesize($_FILES["file_image"]["tmp_name"]);

 

Then check whether the $type == 2 or Not . If it is 2 the image is JPG or JPEG.

 

More details : http://www-eleves-isia.cma.fr/documentation/PhpDoc/function.getimagesize.html

 

 

Link to comment
Share on other sites

i dont think that is right seeing as image/pjpeg does not equal JPEG or jpeg

 

<?php

$text1 = "image/pjpeg";
$text2 = "JPEG";
$text3 = "jpeg";

if($text1 != $text2 or $text != $text3)
{
//redirect
} else
{
// your stuff
}

?>

Link to comment
Share on other sites

Thanks

i put-

 $fieldname = $_FILES['file'];
list($width, $height, $type, $attr) = getimagesize($fieldname);

and i get-

Notice: Array to string conversion in C:\Program Files\xampp\htdocs\epeople\editphoto.php on line 42

 

Warning: getimagesize(Array) [function.getimagesize]: failed to open stream: No such file or directory in C:\Program Files\xampp\htdocs\epeople\editphoto.php on line 42

 

Link to comment
Share on other sites

I think, there is an error in your code for checking the Image name.. Please go through the site and understand the file uploading.

 

Please go through this lines of code.

 

here "file_image" is the name of the image field.

 

if($_FILES["file_image"]["name"])

{

$arr  = getimagesize($_FILES["file_image"]["tmp_name"]);

 

list($width, $height, $type, $attr) = getimagesize($_FILES["file_image"]["tmp_name"]);

if($type == FALSE)

{

header("Location:test.php?status=This is not an Image");

exit();

 

}

                elseif($type != 2)

                {

 

header("Location:test.php?status=This is not an JPG or JPEG Image");

        exit();

 

}

 

     

}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.