Hey.
I use uploadify for uploading avatars on my website.
When "JPG" is selected in place of "jpg" it can't upload the picture, it returns "1" in place of the filename.
Now, the question is, how could I strtolower the extension or something, to be able to upload pictures with uppercase extension too?
I tried
$ext = strtolower(pathinfo($_FILES['Filedata']['name'], PATHINFO_EXTENSION));
but it doesn't work.
Any suggestion?:)
Here is the code:
<?php
class ImgResizer
{
var $originalFile = '';
function ImgResizer($originalFile = '') { $this -> originalFile = $originalFile; }
function resize($newWidth, $targetFile)
{
if (empty($newWidth) || empty($targetFile))
{ return false; }
$src = imagecreatefromjpeg($this -> originalFile);
list($width, $height) = getimagesize($this -> originalFile);
$newHeight = ($height / $width) * $newWidth;
$tmp = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
if (file_exists($targetFile)) { unlink($targetFile); }
imagejpeg($tmp, $targetFile, 85);
}
}
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'] . '/';
$ext = pathinfo($_FILES['Filedata']['name'], PATHINFO_EXTENSION); //figures out the extension
$newFileName = md5($tempFile).'.'.$ext; //generates random filename, then adds the file extension
$targetFile = str_replace('//','/',$targetPath) . $newFileName;
move_uploaded_file($tempFile,$targetFile);
$work = new ImgResizer($targetPath.$newFileName);
$work -> resize(1000, $targetPath.$newFileName);
}
if ($newFileName)
echo $newFileName;
else // Required to trigger onComplete function on Mac OSX
echo '1';
?>