views:

444

answers:

5

I am using Uploadify to enable my users to upload images via my web application.

The problem I am having is that every now and then (at what appears to be random) when the progress bar reaches 100% it 'hangs' and does nothing.

I was wondering if any developers familiar with uploadify may have any idea how to solve this? I am in desperate need of some help.

Here is my front-end code:

<javascript>
jQuery(document).ready(function() {
 jQuery("#uploadify").uploadify({
  'uploader'       : 'javascripts/uploadify.swf',
  'script'         : 'upload-file2.php',
  'cancelImg'      : 'css/images/cancel.png',
  'folder'         : 'uploads/personal_images/' + profileOwner,
  'queueID'        : 'fileQueue',
  'auto'           : true,
  'multi'          : true,
  'fileDesc'       : 'Image files',
     'fileExt'        : '*.jpg;*.jpeg;*.gif;*.png',
  'sizeLimit'      : '2097152',
  'onComplete': function(event, queueID, fileObj, response, data)
  {
   processPersonalImage(fileObj.name);
   arrImgNames.push(fileObj.name);
   showUploadedImages(true);
   document.getElementById("photos").style.backgroundImage = "url('css/images/minicam.png')";
  },
  'onAllComplete'  : function()
  {
     completionMessage(arrFailedNames);
     document.getElementById("displayImageButton").style.display = "inline";
     document.getElementById("photos").style.backgroundImage = "url('css/images/minicam.png')";
  },
  'onCancel'  : function()
  {
     arrImgNames.push(fileObj.name);
     arrFailedNames.push(fileObj.name);
     showUploadedImages(false);
  },
  'onError'  : function()
  {
     arrImgNames.push(fileObj.name);
     arrFailedNames.push(fileObj.name);
     showUploadedImages(false);
  }
 });
});
</javascript>

And server side:

 if (!empty($_FILES)) 
 {
  //Get user ID from the file path for use later..
  $userID = getIdFromFilePath($_REQUEST['folder'], 3); 
  $row = mysql_fetch_assoc(getRecentAlbum($userID, "photo_album_personal"));
  $subFolderName = $row['pk'];
     //Prepare target path / file..
  $tempFile = $_FILES['Filedata']['tmp_name'];
  $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/'.$subFolderName.'/';
  $targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
  //Move uploaded file from temp directory to new folder
  move_uploaded_file($tempFile,$targetFile);
  //Now add a record to DB to reflect this personal image..
  if(file_exists($targetFile))
  {
   //add photo record to DB
   $directFilePath = $_REQUEST['folder'] . '/'.$subFolderName.'/' . $_FILES['Filedata']['name'];
   addPersonalPhotoRecordToDb($directFilePath, $row['pk']);
  }
  echo "1";
  die(true);
 }

thanks for any help!!

+1  A: 

this seems like a php error. I'd use Fiddler or a similar problem to view the php response or similar. Check your php error logs, they might shed some light.

mhughes
Heya, I really appreciated your response so thankyou. Fiddler you say? I have not heard of that so I will google it up and let you know how I get on :)With regards to error logs, I am using cheapish hosting (Hostgator) and I dont think I have access.
Matty
Basically, your code never reaches 'echo "1"'. You can echo out breakpoints along the way in your code, and use Firebug to see the results. I've run into this before and you just have to do some old-school debugging until you find the error in your code.
jnunn
Wow thats seriously helpful Jnunn, I will try that first thing in the morning. Where in firebug do you see the server replys? Im used to watching outgoing get/post request
Matty
Hey guys, I am not seeing any response from the PHP file (shown above) in firebug, am I missing something?
Matty
+1 this is the most likely case. If all else fails, try writing the breakpoints into a log file. Also, make sure you have `error_reporting(E_ALL);` turned on so you actually see the error messages.
Pekka
Hi pekka thanks for your reponse.Could you explain a little about what breakpoints are, im un-familir with the term.Also with error reporting, where are the errors written to?many thanks
Matty
A: 

I had a similar problem some time ago with Uploadify (using ASP.Net MVC though) - but you will definitely find some useful info regarding the Uploadify event handling and behaviour in the answer posted! Its available here

Jimbo
HI Jimbo I really appreciate your input. I tried putting "echo 1" right at the top of the script so it would be returned by the script regardless of how far down the script got, but still getting files hanging at random.Ive also tried using firebug to see what the php file returns, but im seeing nothing in the response.Im at a total loss :(
Matty
you wont be able to see the php response with firebug, because the request is generated by flash. That is why i suggested: http://www.fiddler2.com/fiddler2/ so you could see the actual php response
mhughes
Ok I get you now, ill let you guys know what I find!
Matty
Ok, well fiddler reports the following on a successful upload:3110which is bizarre because I thought it was only supposed to return a 1 !
Matty
right ive done some fiddling and the result is that when a file hangs the server returns exactly the same reponse as it did for all the files that completed succesfully:3 1 1 0 Any comments much appreciated :)
Matty
Matty, confirm that your event handers have been declared without inverted commas? I found that Uploadify evens would only sometimes fire if they were declared with `'onComplete': function(event...` - removing inverted commas seems to fix the problem
Jimbo
Hi Jimbo, they have been declared with commas yes, I will remove them and let you know the outcome.Thanks for your help again
Matty
A: 

I have similar problem,anyone solve this?It just stuck on 100% and when click on x to stop-delete upload image I get this message : 'uncaught exception: Error in Actionscript' ?? Any idea?

A: 

These are the steps I would take, in order:

1) Be 100% certain you are getting a 200 response from your server. If not, that is the problem

2) Use the latest and the greatest uplaodify and jquery

3) Check for JS errors (firebug console or browser JS debugger will work)

4) Upgrade your Flash player (if that solves it then you can require a higher version)

5) Put a debug statements in the uploadify source, specifically in the complete handler to be sure it gets called

6) If the progress is reaching 100% but the handler never gets called, I'm afraid the next step may be to dive into the actionscript and use the debugger or some trace statements to figure out where the error is. This can mean that there is a bug in calling the external interface function

7) If you make fixes, submit back to uploadify

Tony
A: 

Chreck your php.ini file for post_max_size parameter. It must be >= upload_max_filesize parameter. For more details see http://php.net/post-max-size.

Viktor