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:


    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;


       $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';

6 Years
Discussion Span
Last Post by nevvermind

When you say 'selected' do you mean that the file type is being specified in a form or where is that selection happening? If the file actually has the jpg specified as upper case in the file name, then that's the way you will want to use it rather than arbitrarily make it lower case. Windows doesn't normally care whether you make it upper or lower case (for the upload part) but other operating systems may. I'd look first at the actual upload part of the process and see if the file is actually getting uploaded or if it can't find the file because the extension is seen to be different. If the file was uploaded OK, then I would do a few echo's at key points in the code shown above to double-check that what is being provided remains consistent (if it started out as upper case that it stays that way).


This is the code.
I can't actually print out variables in the php cuz the js just returns the picture for me.

I hope it is enough

<div id=\"uploadbuttons\"> 
	     <input type=\"file\" name=\"uploadify\" id=\"uploadify\" />							 

/ Uploadify uploader
$(document).ready(function() {
		'uploader'       : 'style/uploadify/uploadify.swf',
		'script'         : 'style/uploadify/uploadify.php',
		'buttonText'     : 'Browse avatar',
		'fileExt'        : '*.jpg;*.jpeg;',
		'fileDesc' 		 : 'Image Allowed - jpg',
		'cancelImg'      : 'style/images/cancel.png',
		'folder'         : 'uploads/avatars',
		'queueID'        : 'fileQueue',
		'method'         : 'GET',
		'auto'           : true,
		'multi'          : false,
	    'onComplete'     : function (evt, queueID, fileObj, response, data) {
				var imgURL = 'uploads/avatars/' + response ;

				$("#uploadedpics").append("<input size='50' type='hidden' name='avatar' value='" + response + "' READONLY/>"); //adds hidden form field to uploadedpics div
				$("#picupload").empty(this).append("<div id=\"success\"> <h1 class='success'>  Image Successfully Uploaded</h1> <br /> <p class='success'> Please fill your security password field then hit \"Change\" in order to your modifications to take effect! </p> </div> "); //clears browse button, replaces with success message
				$("#thumb").append("<script type=\"text/javascript\">" + "$(function() { $('#image"+queueID+"').lightBox({ fixedNavigation  : true, imageLoading  : 'style/images/loader.gif' }); });" + "</" + "script> <div id='info'> <p class='info'>  The avatar you just uploaded: </p> </div> <a style='margin-left: 20px' id='image"+queueID+"' href='" + imgURL + "'><img width='150' src='" + imgURL + "' alt='asd'></a> ");


Use this:

$ext = strtolower(pathinfo("{$_FILES['Filedata']['name']}", PATHINFO_EXTENSION));

Still, I'd go with chrishea's suggestion.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.