LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-09-2017, 05:24 PM   #1
MartenH
Member
 
Registered: Jul 2005
Location: Lund, Sweden
Distribution: Debian
Posts: 78

Rep: Reputation: 23
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!
 
Old 10-10-2017, 09:56 AM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885Reputation: 4885
You have to tell the PHP interpreter that it has access to that folder by changing the open_basedir setting in your php.ini.
 
Old 10-10-2017, 01:47 PM   #3
MartenH
Member
 
Registered: Jul 2005
Location: Lund, Sweden
Distribution: Debian
Posts: 78

Original Poster
Rep: Reputation: 23
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] PHP: www.domain.com/index.php?page=xxxxx security Snark1994 Linux - Security 3 12-14-2011 08:45 AM
How to store pictures in a MySQL database in PHP resetreset Programming 2 04-30-2010 12:02 PM
php array into many pictures secretlydead Programming 1 10-10-2007 07:12 AM
problems accessing site with www.look.ca as isp ftcnt General 6 06-21-2004 04:42 PM
accessing my apache from the www toddncl Linux - Networking 2 06-10-2004 09:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration