473,796 Members | 2,522 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reversing an upload in AJAX

21 New Member
Hey

I've designed an intranet site where users can upload documents (called 'resources') as part of a knowledge base. Part of the functionality of said site is that privilaged users can edit the documents in the system. This involves uploading a new file for a 'resource'. However, after a user has performed their editing, they are asked to confirm their changes (in a page called confirm.php). When confirm.php loads, the new file upload is performed but the neccessary changes to the database are not performed until the user clicks 'Confirm' (which brings them to update.php). This works fine so long as the user validates their changes on confirm.php - but if the user clicks 'Undo' on confirm.php, the uploaded document stays on the network (although it is not connected to any resource) and the user is directed back to editing the Resource.

I wish to design an AJAX function that will receive the uploaded files network path. I believe that this should be as simple as attaching an onclick command to the undo button, like so:


[HTML]<INPUT TYPE='BUTTON' VALUE='Undo' onClick='revers eUpload($upload edFileTargetPat h);'>[/HTML]

and then writing the AJAX function which will pass this target path into a php file called something like 'cancelUpload.p hp' which will be able to unlink the uploaded file. So far I have used the following AJAX code with no joy:

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript" type="text/javascript">
  2. <!--
  3. //Browser Support Code
  4.  
  5. function reverseUpload(filePath){
  6.         var ajaxRequest;  // The variable that makes Ajax possible!
  7.  
  8.         try{
  9.                 // Opera 8.0+, Firefox, Safari
  10.                 ajaxRequest = new XMLHttpRequest();
  11.         } catch (e){
  12.                 // Internet Explorer Browsers
  13.                 try{
  14.                         ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
  15.                 } catch (e) {
  16.                         try{
  17.                                 ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
  18.                         } catch (e){
  19.                                 // Something went wrong
  20.                                 alert("Your browser broke!");
  21.                                 return false;
  22.                         }
  23.                 }
  24.         }
  25.         // Create a function that will receive data sent from the server
  26.         ajaxRequest.onreadystatechange = function(){
  27.                 if(ajaxRequest.readyState == 4){
  28.  
  29.                 }
  30.         }
  31.         ajaxRequest.open("GET", "cancelUpload.php?path="+filePath, true);
  32.         ajaxRequest.send(null);
  33. }
  34.  
  35. //-->
  36. </script>
and the cancelUpload.ph p file looks like this:


[PHP]$path = $_GET['targetPath'];

unlink($path);

ECHO "blah";[/PHP]


Any help would be greatly appreciated. Thanks!
Mar 13 '08 #1
8 1670
sivakumarsubash
2 New Member
sorry i dont have any idea
Mar 13 '08 #2
gearoid
21 New Member
Anybody have any suggestions?
Mar 14 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
sorry i dont have any idea
If you didn't have any idea, there was no need to tell the world that refreshing pearl of wisdom. By answering, you removed this thread from the unanswered list thereby giving it less chance of receiving attention.
Mar 14 '08 #4
acoder
16,027 Recognized Expert Moderator MVP
I've designed an intranet site where users can upload documents (called 'resources') as part of a knowledge base. Part of the functionality of said site is that privilaged users can edit the documents in the system. This involves uploading a new file for a 'resource'. However, after a user has performed their editing, they are asked to confirm their changes (in a page called confirm.php). When confirm.php loads, the new file upload is performed but the neccessary changes to the database are not performed until the user clicks 'Confirm' (which brings them to update.php). This works fine so long as the user validates their changes on confirm.php - but if the user clicks 'Undo' on confirm.php, the uploaded document stays on the network (although it is not connected to any resource) and the user is directed back to editing the Resource.
Why not just delete the document using the Undo button in confirm.php?

Just a note: you should use the POST method when making changes on the server.
Mar 14 '08 #5
gearoid
21 New Member
Why not just delete the document using the Undo button in confirm.php?

Just a note: you should use the POST method when making changes on the server.
Thanks for the tip.

When you say "delete the document using the Undo button" do you mean: create another form on the page, have the target file as a hidden field and then have a Submit button (labelled 'Undo') call a page which unlinks the file?

Seems like a much simpler solution than what I'd planned - thanks a lot!
Mar 18 '08 #6
acoder
16,027 Recognized Expert Moderator MVP
When you say "delete the document using the Undo button" do you mean: create another form on the page, have the target file as a hidden field and then have a Submit button (labelled 'Undo') call a page which unlinks the file?

Seems like a much simpler solution than what I'd planned - thanks a lot!
That sounds about right. Let us know if you have any problems with it.
Mar 18 '08 #7
gearoid
21 New Member
That sounds about right. Let us know if you have any problems with it.
Working perfectly. Thanks again!
Mar 18 '08 #8
acoder
16,027 Recognized Expert Moderator MVP
You're welcome. Glad you got it working!
Mar 18 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

6
10105
by: Marko Vuksanovic | last post by:
I am trying to implement a file upload progress indicator (doesn't have to be a progress bar) using atlas... I do realize that the indicator cannot be implemented using Update panel control, but is it possible to implement it using some other control, for example a floating window?
3
20079
by: Senthil | last post by:
Hi all I'm new in ajax. How to upload a image using ajax..
3
19885
by: markus.rietzler | last post by:
i want to do (multiple) file upload(s) and display a progress bar. with firefox and safari it is no problem at all. only IE makes some problems. my script is based on ajax-uploader, which can be found at www.srmiles.com/freestuff/ajax_file_uploader/ . you can do multiple file uploads. each upload will have it's own "form"-tag, so that each file is uploaded for its own. could be a good solution if there are "big" uploads.
9
3905
by: Steve Poe | last post by:
I work for an animal hospital trying to use PHP to store an animal's dental x-rays to a file server. I can browse for the xray on the local desktop computer then click "Upload Image". This works fine. The doctors want fewer steps to follow. So, it was asked if I can configure the browser to load/submit the image 'xray.tif' each time they click "Upload Image" instead of the doctor/animal technician having to look for for dental x-ray...
3
3272
by: Ken1 | last post by:
Hello, Does anyone know of an easy to implement ajax upload script for php which also has a progress bar. If possible I'd like it to be able to remove already uploaded files and do minor manipulations... Thanks.
3
4516
by: kksandeep | last post by:
i am using this three files to uplod file. i got this file from net but i think these have some error. i am new to this field plz help the script i found is some helpful but not too that i need my objective is this that when i uplod a file it should be desply on same page with ajax uplod after when i refresh page this should be not remains longer and on clicking other image its replase previous image plz help how i can do this the...
1
3957
by: kksandeep | last post by:
i am using this three files to uplod file. i got this file from net but i think these have some error. i am new to this field plz help the script i found is some helpful but not too that i need my objective is this that when i uplod a file it should be desply on same page with ajax uplod after when i refresh page this should be not remains longer and on clicking other image its replase previous image plz help how i can do this the...
1
2041
by: gamernaveen | last post by:
Hey guys , am just getting into the AJAX scene and am a noob. I am really worried about Ajax upload , cant figure it out. I have a basic html form , like this <form action="upload.php" method="POST" ENCTYPE="multipart/form-data"> *<input type="text" name="name" value="Nick/Name"/><br/><input type="password" name="pass" value="password"/><br/> <textarea rows="5" cols="15" value="comments" name="comments"/><br/><input type="file"...
11
8414
by: kj | last post by:
I would like to convert a form that currently uses the traditional CGI sequence (i.e. the action associated with the form sends a POST request to a server-side CGI script) to one that uses AJAX to send a JSON-encoded request to a remote web service. The stumbling block I'm running into is that one of the inputs in the form is a file upload element, and I can't figure out how to include the data from the specified file in the JSON...
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9531
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10237
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10187
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10018
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9055
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7553
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.