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:
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!
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:
Code:
<script language="javascript" type="text/javascript">
<!--
//Browser Support Code
function reverseUpload(filePath){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
}
}
ajaxRequest.open("GET", "cancelUpload.php?path="+filePath, true);
ajaxRequest.send(null);
}
//-->
</script>
[PHP]$path = $_GET['targetPath'];
unlink($path);
ECHO "blah";[/PHP]
Any help would be greatly appreciated. Thanks!
Comment