LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Accessing pictures outside of www with php (https://www.linuxquestions.org/questions/linux-newbie-8/accessing-pictures-outside-of-www-with-php-4175615338/)

MartenH 10-09-2017 05:24 PM

Accessing pictures outside of www with php
 
Hello,

I'm running apache and using php to deliver a page. I am using a function to randomly serve a picture through a php page (/var/www/html/pf) when called as such:
PHP Code:

<?php
// open the file in a binary mode

function random_pic($dir 'apa')
{
    
$files glob($dir '/*.*');
    
$file array_rand($files);
    return 
$files[$file];
    
}

$name random_pic();

$fp fopen($name'rb');

// send the right headers
header("Content-Type: image/jpeg");
header("Content-Length: " filesize($name));

// dump the picture and stop the script
fpassthru($fp);
exit;
?>

I have granted the Apache user access to the apa folder and pictures within it and it works fine.

But now I want to replace the folder 'apa' with a symlink to a folder outside of www, more specifically /shares/bilder/Wille

I have tried reading up on it and messed around with <Directory> ans <Alias> tags in the Apache config, I've added a symlink to the /shares/bilder/Wille folder, I've set access rights on both symlink and the real folder/files but nothing works. The glob returns an empty array whatever I do.

I'm assuming I'm simply not able to set it up correctly with the correct configuration of all the above. So.. I'm hoping someone where can give me instructions on how to get it to work.

Thanks in advance!

TobiSGD 10-10-2017 09:56 AM

You have to tell the PHP interpreter that it has access to that folder by changing the open_basedir setting in your php.ini.

MartenH 10-10-2017 01:47 PM

Thanks for the suggestion TobiSGD. But adding entries there only mean I block php execution in all other places and did not help me. IT could come in handy some other time though so not wasted information!

For everyone else -I'm closing this thread since I got it working. I can't say I know exactly how but a combination of the correct <Directory> tags in apache config, removing a broken .htaccess file (thansk to /var/log/apache2/error.log and mostl likely some more access right configurations.

Clsoing thread.


All times are GMT -5. The time now is 02:03 PM.