Solved

linux/php image path on read directory

Posted on 2011-03-15
2
602 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

691 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