Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a problem with Multisite, as we all know multisite with sub directories looks like this "www.example.com/site1" etc.

I am using a custom script linked with foobox that when someone clicks on "Download Image" it loads my "example.com/get_file.php" on the main directory of the server.

However since Foobox is a sitewide plugin, it loads the script and is currently having problems with being able to grab the image url since Multisite auto adds the "/site1/" into the url and all my files are located on the base domain eg "example.com/images" instead of "example.com/wp-content/site1" etc

This is part of the script to grab the images:

$file = explode('example.com', $_SERVER['QUERY_STRING']);
$file = end($file);
$file = str_replace('//', '/', '/home/www/example.com/media/images/'.$file);
$file = rawurldecode($file);
if(file_exists($file)) {
header("Content-Type: $ctype");
header("Content-Disposition: attachment; filename=\"".basename($file)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($file));
readfile($file);
} else {
    echo "File $file dosn't exists...";
}
exit();

I am looking for a way for it to just grab the Image name and the folder where the image is held in.

eg: "example.com/media/images/FOLDERNAME/FILENAME.JPG

and my script can replace all text before the folder name to path it to the base directory.

Edit: So after reading about this, the question is:

"How do I grab the Parent folder the file is in and also grab the filename"

Edit: Have just tried this and not sure why it is not working

$file = str_replace('//', '/', '/home/www/example.net/media/images/' .dirname(__FILE__),'/' .basename($file));

Resources: http://stackoverflow.com/questions/8980244/how-to-get-just-the-name-of-the-parent-folder-in-the-directory-where-a-script-is

http://stackoverflow.com/questions/2601885/php-get-only-directory-path

share|improve this question
    
$file = str_replace('//', '/', '/home/www/example.net/media/images/' .dirname(__FILE__),'/' . basename($file)); -- Well, for a start, the optional 4th parameter in str_replace() should be an integer, not a string. Did you mean $file = str_replace('//', '/', '/home/www/example.net/media/images/' .dirname(__FILE__) . '/' .basename($file)); instead? If so, is that a typo in your site's code, or just in the code posted here? –  Pat J Apr 13 at 5:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.