Page 1 of 1
How to delete a file on the server?
Posted: Wed Mar 10, 2021 10:52 pm
by AMpos
How can I delete a file on the server side?
I know the filenames on a folder in my server, and I want to delete some of them.
I am trying to do it with my program calling a custom created .php file, but no luck yet.
I have tried the forum search with no luck.
Code: Select all
current server content:
myprog.htm
myprog.js
delete.php
files/...
.../file1.jpg
.../file2.jpg
I want to delete "files/file1.jpg" for example.
Re: How to delete a file on the server?
Posted: Thu Mar 11, 2021 12:08 am
by AMpos
Solved!
Code: Select all
Procedure deleteFileCallback(Success, Filename.s, Result.s)
If success=1
Debug "OK:"+filename
Else
Debug "Sucess:"+Success
EndIf
EndProcedure
Procedure deleteFile(File.s)
Define url.s="deletefile.php"
Define callback=@deleteFileCallback()
Protected filename.s=file
! var formData = new FormData();
! formData.append('filename', v_filename);
! $.ajax({
! url: v_url,
! data: formData,
! contentType: false,
! processData: false,
! method: 'POST',
! type: 'POST',
! success: function(response) { v_callback(true, v_filename, response) },
! error: function(xhr, status, error) { v_callback(false, v_filename, xhr.statusText) },
! });
EndProcedure
deleteFile("File_to_delete")
and you have to have also this php file on your server, named "deletefile.php":
Code: Select all
<?php
$file = $_POST["filename"];
echo $file;
unlink($file);
?>
(edited for a simpler spiderbasic procedures)
Re: How to delete a file on the server?
Posted: Sat Mar 13, 2021 11:40 am
by T4r4ntul4
Just a thought:
If i can locate that 'deletefile.php' on your server i can potentially delete your whole website with that...
I dont think its a good idea to let a Spiderbasic script (what can be read by the user, and thus see the link to 'deletefile.php') communicate with that php file.
Just my two cents.
Re: How to delete a file on the server?
Posted: Sun Mar 14, 2021 5:42 pm
by AMpos
You are right, I'm going to change to limit it a bit.