Problem with Extension ... .txt instead of .jpg

See all posts Reply

Problem with Extension ... .txt instead of .jpg new!
by DJo, 15 years, 10 months ago
Hello,

I've got an error when I'm uploading a picture with Symfony Admin form.
I upload a JPG file, then I manage this image with your great classe but the file get a .txt extension instead of a .jpg one.
When I force convert jpg, the .jpg extension is well displayed, but I would like to use PNG files too.

Do you have an idea to soluce my problem ?

Thanks a lot.Reply
Re: Problem with Extension ... .txt instead of .jpg new!
by colin, 15 years, 10 months ago
Can you copy here the log produced by the class?Reply
Re: Problem with Extension ... .txt instead of .jpg new!
by DJo, 15 years, 10 months ago
Sure, here is it:

system information
- GD version : 2.0.34
- supported image types : png jpg gif bmp
- open_basedir : no restriction
- language : en_GB
source is a local file /tmp/phppj3C9h
- local file name OK
- MIME type detected as image/jpeg by UNIX file() command
- source variables
file_src_name : phppj3C9h
file_src_name_body : phppj3C9h
file_src_name_ext :
file_src_pathname : /tmp/phppj3C9h
file_src_mime : image/jpeg
file_src_size : 36753 (max= 8388608)
file_src_error : 0
- source file is an image
image_src_x : 1000
image_src_y : 804
image_src_pixels : 804000
image_src_type : jpg
image_src_bits : 8
process file to /var/www/*************/web/images/produits/
- file size OK
- script phppj3C9h renamed as phppj3C9h.txt!
- file mime OK : text/plain
- new file name body : mini_1
- file name safe format
- destination variables
file_dst_path : /var/www/*************/web/images/produits/
file_dst_name_body : mini_1
file_dst_name_ext : txt
- image operation, keep extension
- no auto_rename if same filename exists
- destination file details
file_dst_name : mini_1.txt
file_dst_pathname : /var/www/*************/web/images/produits/mini_1.txt
- no overwrite checking
- image resizing or conversion wanted
- source image is JPEG
- setting destination file type to txt
- resizing...
use plain sizes
resized image object created
image_src_x y : 1000 x 804
image_dst_x y : 1 x 1
- converting...
fills in transparency with default color
- saving image...
JPEG image created
image objects destroyed
- process OK
Reply
Re: Problem with Extension ... .txt instead of .jpg new!
by DJo, 15 years, 10 months ago
And my log with a PNG File:

system information
- GD version : 2.0.34
- supported image types : png jpg gif bmp
- open_basedir : no restriction
- language : en_GB
source is a local file /tmp/phpopCwHr
- local file name OK
- MIME type detected as image/png by UNIX file() command
- source variables
file_src_name : phpopCwHr
file_src_name_body : phpopCwHr
file_src_name_ext :
file_src_pathname : /tmp/phpopCwHr
file_src_mime : image/png
file_src_size : 102997 (max= 8388608)
file_src_error : 0
- source file is an image
image_src_x : 450
image_src_y : 300
image_src_pixels : 135000
image_src_type : png
image_src_bits : 8
process file to /var/www/*************/web/images/produits/galerie/
- file size OK
- script phpopCwHr renamed as phpopCwHr.txt!
- file mime OK : text/plain
- new file name body : img_2-5
- file name safe format
- destination variables
file_dst_path : /var/www/*************/web/images/produits/galerie/
file_dst_name_body : img_2_5
file_dst_name_ext : txt
- image operation, keep extension
- no auto_rename if same filename exists
- destination file details
file_dst_name : img_2_5.txt
file_dst_pathname : /var/www/*************/web/images/produits/galerie/img_2_5.txt
- no overwrite checking
- image resizing or conversion wanted
- source image is PNG
- setting destination file type to txt
- resizing...
calculate y size
resized image object created
image_src_x y : 450 x 300
image_dst_x y : 1 x 1
- converting...
fills in transparency with default color
- saving image...
JPEG image created
image objects destroyed
- process OK


That's really strange.
Do you have an idea ? Is it because I'm using Symfony before ?

This is my PHP Code:
$handle = new upload($file->getTempName());
        
if ($handle->uploaded) {

  // Version mini
  $handle->jpeg_quality = 90;
  $handle->file_new_name_body = "img_".$img->getProduitsId()."-".$img->getId();
  $handle->mime_check = false;
  $handle->auto_create_dir = true;
  $handle->dir_auto_chmod = true;
  $handle->dir_chmod = 0777;
  $handle->image_resize         = true;
  // $handle->image_convert = 'jpg';
  $handle->image_x  = sfConfig::get('app_images_widthprodimages');
  $handle->image_ratio_y  = true;
  $handle->preserve_transparency = true;
  $handle->file_auto_rename = false;
  $handle->file_overwrite = true;
  $handle->Process($path);
  echo $handle->log;

  if ($handle->processed) {
    $handle->clean();
    $finalImage = $handle->file_dst_name;
  } else {
    echo $handle->error;
    $handle->clean();
  }
}

Thanks for your help and for your class !Reply
Re: Problem with Extension ... .txt instead of .jpg new!
by DJo, 15 years, 10 months ago
No idea ?Reply
Re: Problem with Extension ... .txt instead of .jpg new!
by colin, 15 years, 10 months ago
It is indeed strange. It shouldn't behave like this. The MIME type is properly detected as being an image... but for some reason, the source file doesn't have an extension:
file_src_name_ext :
It should be something like:
file_src_name_ext : jpg

Because of this inconsistency, the file is considered as a potential script, and adds the .txt extension.

What is the filename of the file you try to upload? What browser do you use? On which system? Which version of PHP? Apache?

As a temporary fix, you can disable the script checking:
$handle->no_script = false;
Reply
Re: Problem with Extension ... .txt instead of .jpg new!
by DJo, 15 years, 10 months ago
What is the filename of the file you try to upload?
I've tried a lot of different pictures:
wii.jpg
ps3.png
MacBookPro.jpg

What browser do you use?
Firefox 3.0.5

On which system?
Client: Win XP
Serveur: Linux Debian

Which version of PHP?
5.2.8-0.dotdeb.1

Apache?
Apache/2.2.3Reply
Re: Problem with Extension ... .txt instead of .jpg new!
by colin, 15 years, 10 months ago
Strange indeed... It should be working. Did you try to use the no_script parameter?Reply
Re: Problem with Extension ... .txt instead of .jpg new!
by DJo, 15 years, 10 months ago
Now there is no Extensions with no_script.

Strange !Reply
Re: Problem with Extension ... .txt instead of .jpg new!
by colin, 15 years, 10 months ago
You should have something like this in the log (Debian here):
- source variables
    file_src_name         : test.png
    file_src_name_body    : test
    file_src_name_ext     : png
    file_src_pathname     : /tmp/phpWbFkbS
    file_src_mime         : image/png

Would you have a special install of PHP by any chance? Or maybe you run it in safe mode, or in some kind of hardened environment? Can you provide a link to your PHPInfo()?Reply
Re: Problem with Extension ... .txt instead of .jpg new!
by DJo, 15 years, 10 months ago
Nop, but I've got 2 different upload code ...

I just try the other and it's working:

The working code:
$handle = new upload($file->getTempName());
        
if ($handle->uploaded) {
  // Version mini
  $handle->jpeg_quality = 90;
  $handle->file_new_name_body = "img_".$img->getProduitsId()."-".$img->getId();
  $handle->mime_check = false;
  $handle->auto_create_dir = true;
  $handle->dir_auto_chmod = true;
  $handle->dir_chmod = 0777;
  $handle->image_resize         = true;
  // $handle->image_convert = 'jpg';
  $handle->image_x  = sfConfig::get('app_images_widthprodimages');
  $handle->image_ratio_y  = true;
  $handle->preserve_transparency = true;
  $handle->file_auto_rename = false;
  $handle->file_overwrite = true;
  $handle->Process($path);
  if ($handle->processed) {
    $handle->clean();
    $finalImage = $handle->file_dst_name;
  } else {
    echo $handle->error;
    $handle->clean();
  }					       
}

And the code which is not working, extension .txt, but if we display the .txt it's a picture !

if ($handle->uploaded) {
  // Version mini
  $handle->jpeg_quality = 90;
  $handle->file_new_name_body = "mini_".$produit->getId();
  $handle->mime_check = false;
  $handle->auto_create_dir = true;
  $handle->dir_auto_chmod = true;
  $handle->dir_chmod = 0777;
  $handle->image_resize         = true;
  $handle->image_x  = sfConfig::get('app_images_widthproduitsmini', 150);
  $handle->image_y  = sfConfig::get('app_images_heightproduitsmini', 100); 
  $handle->file_auto_rename = false;
  $handle->file_overwrite = true;
  $handle->Process($path);
  // Version large
  $handle->jpeg_quality = 90;
  $handle->file_new_name_body = $produit->getId();
  $handle->mime_check = false;
  $handle->auto_create_dir = true;
  $handle->dir_auto_chmod = true;
  $handle->dir_chmod = 0777;
  $handle->image_resize         = true;
  $handle->image_x  = sfConfig::get('app_images_widthproduitsnormal', 450);
  $handle->image_y  = sfConfig::get('app_images_heightproduitsnormal', 300);
  $handle->preserve_transparency = true;
  $handle->file_auto_rename = false;
  $handle->file_overwrite = true;
  $handle->Process($path);
   
  if ($handle->processed) {
    $handle->clean();
    $finalImage = $handle->file_dst_name;
  } else {
    echo $handle->error;
    $handle->clean();
  }
}

But if I add convert jpg, it's working well ...Reply
Re: Problem with Extension ... .txt instead of .jpg new!
by DJo, 15 years, 10 months ago
And the second code produce 2 files:
mini_3.txt and 3.txt.txt

If you put <img src='3.txt.txt' /> It's working ... but not the good extension.Reply