Solved

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

Posted on 2014-07-25
2
855 Views
Last Modified: 2014-07-25
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';
      }

?>
0
Comment
Question by:kadin
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40220625
Use .abort() on the ajax object
Normally you don't need to do anything as the PHP script will abort if it fails to send something to the browser
0
 

Author Comment

by:kadin
ID: 40220645
Thanks. I will give it a try.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
I'm a Human captcha checkbox 13 40
Clear input text 15 26
replacing inline javascript with jquery 4 45
Echo'd values in dropdowns 6 29
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question