Solved

linux/php image path on read directory

Posted on 2011-03-15
2
599 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
ID: 35140560
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
ID: 35140580
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

806 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