Jump to content

[SOLVED] scandir and chdir problem


jaxdevil

Recommended Posts

I am having a strange problem. On my local wamp installation this below code works, and on my web host it does not. The bottom code ($files1) works on my web host but not on my wamp. So where it works on one system it doesn't work on the other, and where it doesn't work on one system it does work on the other. Its very odd. I turned error reporting on and receive this message:

 

Warning: chdir() [function.chdir]: No such file or directory (errno 2) in /home/temp/public_html/folder_paths.php on line 35

 

Warning: scandir(7101-7200) [function.scandir]: failed to open dir: No such file or directory in /home/temp/public_html/folder_paths.php on line 36

 

for each iteration of the foreach statement where it runs a new scandir and chdir for each path that is stored in the database table. And on the bottom code I get that error, but only on the last test code ($file1) where it is looking for the folder in the same directory it is in, the main code works like a charm on my local host, it grabs the folder paths, changes directory to them, and scans the contents, adding them to the array. I put my code right below, and under that a copy of the output on my remote host, and then a copy of the output on my local wamp install.

 

<?php

// Mysql connection string
session_start();
require('bouncer/inner_security_check.php');


// Pull seperator passed from last page. If no seperator then we are on the first page so the seperator is 0 (this will pull rows 1-100 for 100, and for 100 it will pull 101-200, etc.)

$seperator_num = $_GET['seperator_num'];
if ($seperator_num='') {
$seperator_num='0';
}

$offset = 1;
$rowsPerPage = '100';
// Now we are going to access the folders_table and put each folders full path one at a time into an array
$query = "SELECT `folder_path` FROM `master_templates` LIMIT $offset, $rowsPerPage";
$result = mysql_query($query) or die('Error:'.mysql_error());
$my_count = mysql_num_rows($query);
while($row = mysql_fetch_array($result)){
$folders[] = $row['folder_path'];
}


print_r($folders);
// Now we are going to iterate through these array values (the folder paths) and scan directory on them. Adding an array to the array using their entry as the arrays id.
foreach($folders as $key => $value) {

$full_path = $value;
$marker = strrpos( $value, '/' ) ;
$value2 = substr( $value, 0, $marker ) ;  
$value = substr( $value, $marker ) ;  
$directory = $_SERVER['DOCUMENT_ROOT'].$value2;
$folder = preg_replace('/\//', '', $value);
echo "Directory: ".$directory;
chdir($directory);
$folder_data[$full_path] = scandir($folder);
}
print_r($folder_data);
echo "<br>";

$files1 = scandir("cronjobs");
print_r($files1);
?>

 

Link to the 'view source' contents of the web server install of the above, including ERRORS ALL on. (this is the one that doesn't work). Also includes a link to a html version of my phpinfo page

http://temp-server.info/folder_paths.txt

http://temp-server.info/phpinfo.php.htm

 

Link to the 'view source' contents of the local WAMP install of the above, including ERRORS ALL on (this one is working how I want). Also includes an html generation of my local wamp phpinfo page.

http://temp-server.info/folder_paths_local_wamp.txt

http://temp-server.info/phpinfo_local_wamp.php.htm

 

Anyone have an idea or see what I am missing?

 

 

Link to comment
Share on other sites

When you view the directory, in your echo, is it correct?  It probably works on one and not the other because the paths are not the same or you don't have permissions to scan a particular folder on one or the other.

Link to comment
Share on other sites

That was sort of it, I did not have mod_speling module active in apache on the external web host, and it is active in wamp. The urls it  is pulling were all in lower case and the diretcory is a clone of the files on the local files server, so they were a mix of capital and lowercase characters. Added mod_speling and it works perfect now :)

 

Thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.