[PHPwestoz] File Upload issues

Nicolas Connault nicou at sweetpeadesigns.com.au
Tue Feb 15 16:08:01 UTC 2005


Greater Wyrm wrote:

>
> can anyone point me to  an example on how to extract the file 
> extention from the uploaded file so I can rename the file with the 
> appropriate extention?

I'm not sure I understand what you mean, but I'll give it a go anyway: 
You can retrieve the file extension of an image file two ways:

   1. substr($file,-3); // This gives you the last three characters at
      the end of the filename. Not foolproof
   2. Get the actual filetype, independent of the extension:
      $image_info = getimagesize($file);
      $file_type = $image_info[2];
      // Values of $file_type : 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 =
      PSD, 6 = BMP, 7 = TIFF(intel byte order),
      // 8 = TIFF(motorola byte order), 9 = JPC, 10 = JP2, 11 = JPX, 12
      = JB2, 13 = SWC,
      // 14 = IFF, 15 = WBMP, 16 = XBM

Is that of any help?

Cheers,

Nicolas




More information about the PHPwestoz mailing list