kadin
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.addEventListen er('progre ss', progressHandler, false);
ajax.addEventListener('loa d', completeHandler, false);
ajax.addEventListener('err or', errorHandler, false);
ajax.addEventListener('abo rt', abortHandler, false);
ajax.open('post', '/upload_file.php', true);
function abortHandler(event) {
document.getElementById('e lement-inf o').innerH TML = '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($fileTm pLoc, $filename);
if ($success) {
echo 'upload complete.';
} else {
echo 'try again';
}
?>
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.addEventListen
ajax.addEventListener('loa
ajax.addEventListener('err
ajax.addEventListener('abo
ajax.open('post', '/upload_file.php', true);
function abortHandler(event) {
document.getElementById('e
}
<?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($fileTm
if ($success) {
echo 'upload complete.';
} else {
echo 'try again';
}
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER