How to delete a file on the server?

Just starting out? Need help? Post your questions and find answers here.
AMpos
Posts: 42
Joined: Mon Aug 03, 2020 5:15 pm

How to delete a file on the server?

Post 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.
AMpos
Posts: 42
Joined: Mon Aug 03, 2020 5:15 pm

Re: How to delete a file on the server?

Post 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)
User avatar
T4r4ntul4
Posts: 132
Joined: Wed May 21, 2014 1:57 pm
Location: Netherlands
Contact:

Re: How to delete a file on the server?

Post 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.
AMpos
Posts: 42
Joined: Mon Aug 03, 2020 5:15 pm

Re: How to delete a file on the server?

Post by AMpos »

You are right, I'm going to change to limit it a bit.
Post Reply