Link to home
Start Free TrialLog in
Avatar of kadin
kadinFlag for United States of America

asked on

I created an ajax file upload with progress bar. Now I need a cancel button.

I currently have a working FLEX/Actionscript solution with progress bar and cancel button, but it's a little bulky and time consuming to trouble shoot. I created an AJAX/PHP video file upload yesterday and it works nicely.

I need a way to cancel an (ajax-php) video file upload. Can I just use the javaScript function abort() and then redirect the user to a different page or will that leave the server and php file in a messy situation with a half uploaded file? Any advise would be appreciated. Thanks.

I posted just some of the code.
ajax.upload.addEventListener('progress', progressHandler, false);
ajax.addEventListener('load', completeHandler, false);
ajax.addEventListener('error', errorHandler, false);
ajax.addEventListener('abort', abortHandler, false);
ajax.open('post', '/upload_file.php', true);

function abortHandler(event) {
      document.getElementById('element-info').innerHTML = 'Upload canceled';
}

<?php
$filename = $_FILES['file']['name'];
$fileTmpLoc = $_FILES['file']['tmp_name'];
$fileType = $_FILES['file']['type'];
$fileSize = $_FILES['file']['size'];
$fileErroeMsg = $_FILES['file']['error'];

if(!$fileTmpLoc) {'Please browse for a file before clicking the arrow button.'; exit;}

$success = move_uploaded_file($fileTmpLoc, $filename);

if ($success) {
      echo 'upload complete.';
} else {
            echo 'try again';
      }

?>
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kadin

ASKER

Thanks. I will give it a try.