[PHP] Help w/Bug

2004-03-31 Thread Joey
While running the below code, a form passes the image name to this code, the
values when executed are as follows:
 
Step1: upload_file_type: 
Step1: upload_file: C:\\Documents and Settings\\jack.IISG\\Desktop\\BVP.jpg
Step1: extention: 

Step2: upload_file_type: 
Step2: upload_file: C:\\Documents and Settings\\jack.IISG\\Desktop\\BVP.jpg
Step2: extention: image/pjpeg

And what happens is it keeps giving me the following error:
 
Not a Valid Image Extension, .jpg only!
 
 
This is going to be something stupid that I am being blind to... any help
appreciated!
 
 
--- Code Below 
 
 
//The file to be uploaded
global $upload_file_name;
 
echo Step1: upload_file_type:  . $upload_file_type .br;
echo Step1: upload_file:  . $upload_file.br;
echo Step1: extention:  . $extention .br;
 
if($upload_file !=)
{
//image size esle will ignore ...
$img_max_width=750;
$img_max_height=750;
$extention=  
$file_type1 = image/pjpeg;
$file_type2 = image/jpeg;
$file_type3 = image/gif;
$file_type4 = image/jpg;
 
echo Step2: upload_file_type:  . $upload_file_type .br;
echo Step2: upload_file:  . $upload_file.br;
echo Step2: extention:  . $extention .br;
 
if (($upload_file_type == $file_type1) or ($upload_file_type == $file_type2)
or ($upload_file_type == $file_type3) or ($upload_file_type == $file_type4))
{
$ext=strrchr($upload_file_name, .);//
 
$picture_name=get_param(first_name)._.get_param(last_name);
 
$picture_name=str_replace( ,_,$picture_name);
 
$picture_name=explode(.,$picture_name);
 
$upload_file_name=$picture_name[0]..$ext;
 
$image_url=images/contacts/.$upload_file_name;
 
@copy($upload_file, images/contacts/.$upload_file_name); 
chmod(images/contacts/.$upload_file_name,0777);
 
$image_test_size = images/contacts/.$upload_file_name;
$image_size = getimagesize($image_test_size);
$img_width = (($image_size[0]));
$img_height = (($image_size[1]));
if (($img_width  $img_max_width or $img_height  $img_max_height)) {
   unlink(images/contacts/.$upload_file_name);
}
 
} else {
   echo Not a Valid Image Extension, .jpg only!;
}
}

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Help w/Bug

2004-03-31 Thread Chris W. Parker
Joey mailto:[EMAIL PROTECTED]
on Wednesday, March 31, 2004 2:54 PM said:

 Step1: upload_file_type:
 Step1: upload_file: C:\\Documents and
 Settings\\jack.IISG\\Desktop\\BVP.jpg Step1: extention:
 
 Step2: upload_file_type:
 Step2: upload_file: C:\\Documents and
 Settings\\jack.IISG\\Desktop\\BVP.jpg Step2: extention: image/pjpeg

in both cases $upload_file_type is empty. you're comparing
$upload_file_type to $file_type1,2,3,4. of course there won't be a
match.

at least, that's what it looks like to me at a cursory glance.


hth,
chris.

p.s. extention != extension

:)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Help w/Bug

2004-03-31 Thread Curt Zirzow
* Thus wrote Joey ([EMAIL PROTECTED]):
 ...
  
 if($upload_file !=)
 {
 //image size esle will ignore ...
 $img_max_width=750;
 $img_max_height=750;
 $extention=  
 $file_type1 = image/pjpeg;

Here is your bug as you described. $extention is assigned the
value of $file_type1 after it is assigned 'image/pjpeg'.


 ...

 if (($upload_file_type == $file_type1) or ($upload_file_type == $file_type2)
 or ($upload_file_type == $file_type3) or ($upload_file_type == $file_type4))
 {

  There are several more elegant solutions to testing to ensure
  that the file_type is good, one of them is:

  $accept_file_types = array('image/jpeg', 'image/gif');

  if (in_array($upload_file_type, $accept_file_types) ) 
  {


 ...
  
 $image_url=images/contacts/.$upload_file_name;
  
 @copy($upload_file, images/contacts/.$upload_file_name); 

see http://php.net/move_uploaded_file
about the proper way to handle uploaded files. 



 chmod(images/contacts/.$upload_file_name,0777);

0644 should be used. 777 is evil, contrary to common belief.

Curt
-- 
I used to think I was indecisive, but now I'm not so sure.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php