[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PHPwestoz] File Upload issues



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