Search code examples
phpflashjqueryfile-uploadswfupload

Issue with an ajax uploader


I'm using a flash/ajax file upload in php based on this site - http://blog.codeville.net/2008/11/24/jquery-ajax-uploader-plugin-with-progress-bar/

There is a little inconsistency in the behavior I'm getting.

One result is having the process hang at what looks like 100%. (I can cancel and do other things on the page but I just doesn't go further.)

The other is I hit the upload_success_handler but the file is still not uploaded to the server. I even temporarily changed my permissions to 777 to rule all that out, it still doesn't get uploaded.

If anyone has any experience with this type of thing, I would like to ask what gets sent to the ajax called file and how does it get sent (get/post). Also, what exactly do I need to do on the file called by ajax and what do I have to return? Do I "return" the file name just by echoing it, or would I actually use the "return" command as if it was a function. All it says on the blog Is following is

The handler should save the uploaded file to disk, then return a unique token, such as a GUID or filename, to will identify the file you just uploaded.

Currently what I have for my code in that file is as so

<?php
ini_set('post_max_size', 510000000);
ini_set('upload_max_filesize', 500000000);
ini_set('max_input_time', 20);
ini_set('memory_limit', 520000000);

if (!empty($_FILES['file']['name'])) //checking if file upload box contains a value
{

    $saveDirectory = 'videos/';         //name of folder to upload to
    $tempName = $_FILES['file']['tmp_name'];    //getting the temp name on server
    $fileName1 = $_FILES['file']['name'];       //getting file name on users computer

    $test = array();
    $test = explode(".", $fileName1);
    if((count($test) > 2) || ($test[1] != "avi" && $test[1] != "AVI" && $test[1] != "flv" && $test[1] != "FLV" && $test[1] != "mov" && $test[1] != "MOV" && $test[1] != "mpeg" && $test[1] != "MPEG" && $test[1] != "mp4" && $test[1] != "MP4" && $test[1] != "wmv" && $test[1] != "WMV")){
        $err .= "Invalid file type.  Files must have only one period \".\" and be of type .avi .flv .mov .mpeg .mp4 or .wmv";
        echo $err;

    }else{

        $count = 1;
        do{
        $link = $saveDirectory . $count . $fileName1;
        $count++; 
        }while(is_file($link));
        if (move_uploaded_file($tempName, $link))   //Moves the temp file on server
        {                                           //to directory with real name


            echo $link;

        } 
        else 
        {
            $err .= "There was an error while uploading the file.";

            echo $err;
        }
    }
}
?>

Solution

  • I Figured it out. Turns out the javascript from the blog was renaming the file input to something other then what I gave it. Once I adjusted my code accordingly, it worked. I figured that out after It was suggested to me to output the $_FILES[] variables. The output of my asyncupload.php script was ported back into one of the hidden inputs generated by the javascript.

    I just figured I would post my solution for anyone else with this issue.