Web Hosting Talk







View Full Version : Alternative to Unlink?


acctman
03-24-2009, 05:34 PM
Is there an alternative to Unlink that will allow me to delete files from another site user via php coding?

ie. /home/MainSite/public_html/delcode.php should delete /home/Imgsite/public_html/abc123.jpg


i've tried this with unlinky but I get a premission denied error. which i know what it means. each site has a different usergrp and they can't access each other.

Also not that this is my own server.

Steve_Arm
03-24-2009, 05:37 PM
On the same server? Create a script in the other site that will accept a filename
from the other site and will delete the file.
Downside: it has to be a daemon in order to run with the correct permissions.

More easily:
Site A writes a file with delete filenames.
Site B with cron job every 1 minute (?) reads the file and deletes.

acctman
03-24-2009, 05:47 PM
daemon method since i'll need for files to be deleted instantly

sasha
03-24-2009, 06:01 PM
It does not really have to be daemon, simply script that accepts file name as input, ie:
$secret = 'this_is_some_string' ;
if ($_GET['file'] && $_GET['secret'] == $secret) {
// do what needs doing to $_GET['file'] ;
}

Steve_Arm
03-24-2009, 06:03 PM
You mean he will have to curl to the other site?

acctman
03-24-2009, 09:38 PM
You mean he will have to curl to the other site?

i can do something like

submit link
http://mainsite.com/files/process.php?id=39&loc=9229

within the process.php file,
having something like
if ($_GET['id'] && $_GET['loc'] == '' {

and do a http post with curl_exec()? is the the basic idea?

tinkertim
03-25-2009, 08:36 AM
Is there an alternative to Unlink that will allow me to delete files from another site user via php coding?

ie. /home/MainSite/public_html/delcode.php should delete /home/Imgsite/public_html/abc123.jpg


i've tried this with unlinky but I get a premission denied error. which i know what it means. each site has a different usergrp and they can't access each other.

Also not that this is my own server.

I'm assuming both sites comprise two separate users. Joe can not delete Jane's files, unless Jane gives group permissions to those files and Joe is a member of Jane's group.

See usermod -G (or just man usermod). Of course, this assumes php runs as the user .. if not, some kind of daemon with appropriate privileges is likely your best route.

acctman
03-27-2009, 02:13 PM
I'm assuming both sites comprise two separate users. Joe can not delete Jane's files, unless Jane gives group permissions to those files and Joe is a member of Jane's group.

See usermod -G (or just man usermod). Of course, this assumes php runs as the user .. if not, some kind of daemon with appropriate privileges is likely your best route.

read up on usermod... its messy and if you have existing files you have to change permissions for all of them as well.

acctman
03-27-2009, 07:07 PM
It does not really have to be daemon, simply script that accepts file name as input, ie:
$secret = 'this_is_some_string' ;
if ($_GET['file'] && $_GET['secret'] == $secret) {
// do what needs doing to $_GET['file'] ;
}


hi can you help me with setting up file to do this.

sasha
04-01-2009, 11:02 PM
Sorry, was not checking out forum for a couple days

main.php

$secret ='some_secret_string';
$file = 'this.is.some.file.name.jpg';
if ('ok' == file_get_contents('http://anotherdomain.com/deletefile.php?secret='.$secret.'&file=' . urlencode($file))){
// file has been deleted
}


deletefile.php @ anotherdomain.com

$secret ='some_secret_string';

if ($_GET['file'] && $_GET['secret'] == $secret) {
// you have file name in _GET['file']
// make sure it is clean file name and that it exists in some place where if should exist and unlink() it
if (__all_is_good__) {
echo 'ok';
}
}



Only problem with this is that whoever has access to web server logs / stats for "anotherdomain.com" will find out your "secret". As an alternative, as someone mentioned earlier, you could use php curl module and send query string ($file and $secret) as POST data to keep it out of web server logs.

mwatkins
04-02-2009, 02:12 AM
If I were doing this in Python I'd use either XMLRPC or, more likely these days, a simple REST web service, i.e. an HTTP DELETE. That and HTTP Digest authentication would be pretty secure, and also easy to test with command line tools such as ``curl``, e.g.:

curl -u foo:bar --digest -X DELETE http://mydomain.com/api/image/SOMEIMAGEID