linux - Creating SYMLINK with PHP on Hostgator jailed shell - Get Perm Denied error -
so come problem:
givens:
- i have hostgator isp.
- i'm using php 5.5
- the linux box centos
- shared hosting environment
- i professional coder , experienced lamp many years
problems:
- i'm not familiar jailed shell have idea
- i've tried script , have been searching answer
- still stuck...
here's current code:
function getmyfakedir($myfile) { $target = ""; $link = 'content/purchased-items/link'; symlink($target, $link); echo "read link: ". readlink($link); return readlink($link); }
here's called function:
$linktext = getmyfakedir('somepdfthattheusercandownload.pdf');
then pass "$linktext" var phpmailer , wala!!! user clicks download through symlink , i've written code make expire after 24 hours. yeah, got php.net.
so, that's problem....
here's error:
warning: symlink(): permission denied in /homesomewhere/somemasterdir/public_html/webservices/somephpfile.php on line 654
this link 654 above:
symlink($target, $link);
thanks...
figured out.... simple logic!
first had paths wrong. here's corrected code:
//generate symbolic link blows away fake directory each time //a symbolic link created "this" file below $filename = $myfile; //this directory on server... //a randomly named directory created here...step 1 $downloaddir = "/home/somehostdir/public_html/sldktrulwiu2555ivd0fjvdfgdfgdfgdf/"; //any directory not accessible browser - 1 level $safedir = "/home/somehostdir/content/purchased-items/"; //this equivalent of $downloaddir , browser redirected here , download begins $downloadurl = "http://www.thesomedomain.com/sldktrulwiu2555ivd0fjvdfgdfgdfgdf/"; //this fake directory (which type gobbligook , created mess above) $letters = 'abcdefghijklmnopqrstuvwxyz'; srand((double) microtime() * 1000000); $string = ''; ($i = 1; $i <= rand(4, 12); $i++) { $q = rand(1, 24); $string = $string . $letters[$q]; } $handle = opendir($downloaddir); while ($dir = readdir($handle)) { if (is_dir($downloaddir . $dir)) { if ($dir != "." && $dir != "..") { @unlink($downloaddir . $dir . "/" . $filename); @rmdir($downloaddir . $dir); } } } closedir($handle); mkdir($downloaddir . $string, 0777); symlink($safedir . $filename, $downloaddir . $string . "/" . $filename); //header("location: " . $downloadurl . $string . "/" . $filename);
that it.
the result dynamic directory inside "/sldktrulwiu2555ivd0fjvdfgdfgdfgdf/" directory this: "dfsgss/" , "shortcut" real location files are. when file downloaded, , page returns index.html, code blows out fake directory never more seen again. thus, if user wants go back, horrible 404 page error file / has been moved or deleted. bummer.
that's folks. assistance, helped me release error. team work!
Comments
Post a Comment