Solved

linux/php image path on read directory

Posted on 2011-03-15
2
601 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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…
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.

726 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