Solved

linux/php image path on read directory

Posted on 2011-03-15
2
595 Views
Last Modified: 2013-12-13
I figured out how to access folder contents on a Windows (needs full path) but cannot get it on a linux system.  It's on the localhost - you'll see the folder path.
Code is attached:

<?php

$account="account";
$adImage="Images";
$directory = "C:/var/www/Planroom/DataBase/account/Ads/Images";
// tried "/var/www/Planroom/Database/account/Ads/Images" with and without initial slash
// also "/Database/account/Ads/Images" with and without initial slash
$handler = opendir($directory);

if(file_exists($directory)) {

    $results = Array();
    $x=0;

    while ($file = readdir($handler)) {
       if ($file != "." && $file != "..") {
        $results[$x] = $file;
        $x+=1;
      }
    }
    closedir($handler);
echo($x);  // $x=0
}
?>

Open in new window

0
Comment
Question by:dcass
2 Comments
 
LVL 8

Accepted Solution

by:
Rik-Legger earned 500 total points
Comment Utility
Put this line on top of your file:

phpinfo();

Open in new window


and when the file is executed (opened in browser) you search for DOCUMENT_ROOT to how the path to this file is constructed. Try to adjust that in a way to reach you desired location.
0
 
LVL 8

Expert Comment

by:mostart
Comment Utility
Full path with slash at beginning should work in general. Maybe your PHP is configured not to let you access the directory or the directory access rights are not correct.

Do you get an error message ?

Try adding this line to your file before opendir if you do not see any error message:
error_reporting(E_ALL);
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now