Solved

php opendir directory navigation

Posted on 2011-09-30
13
370 Views
Last Modified: 2012-05-12
Hello, I'm having a lot of trouble navigating to an appropriate directory.

Using the command if ($handle = opendir('.')) {

//

}

The dot works perfectly when I want to work with files in the same directory. but i want to go a directory back and then into a new directory, php gives errors. i just want to step out of the 'php" folder and into the "log" folder. I've tried just hardcoding the full address, but php still seems confused. It has this problem whether i put the file in the log folder (and reference it from the file in the php folder, or if I just include the script in the document within the php folder. It only wants to save in it current directory :(

All help is appreciated greatly!
0
Comment
Question by:hibbsusan
  • 9
  • 3
13 Comments
 
LVL 15

Expert Comment

by:ncoo
ID: 36894100
It could be an issue with file permissions.

Have you checked them?

Does PHP have permission to that directory?
0
 
LVL 2

Expert Comment

by:jaxbrian
ID: 36894109
have you tried to put ../log

if you needed to go up two directories it would be ../../
0
 

Author Comment

by:hibbsusan
ID: 36894111
the file writes to the directory when it's in the directory and i just use the dot. are there separate permissions for files accessing from and outside dir?

thanks!
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 

Author Comment

by:hibbsusan
ID: 36894117
../log

yes.
0
 

Author Comment

by:hibbsusan
ID: 36894119
but ../log doesn't work either
0
 
LVL 15

Expert Comment

by:ncoo
ID: 36894176
What error messages does PHP give when trying to access?

error_reporting(0);
0
 

Author Comment

by:hibbsusan
ID: 36894188
Warning: opendir(../php/log/) [function.opendir]: failed to open dir: No such file or directory in /home/iscotest/public_html/php/order_selection_process.php on line 67
/php/order_selection_process.php
0
 

Author Comment

by:hibbsusan
ID: 36894276
it's like it thinks the file is a directory or something...no file in order_selection_process.php.

how could there be? why is it looking in that file? shouldn't it first just be looking in the php folder?

0
 

Author Comment

by:hibbsusan
ID: 36894298
also, i checked file permissions.

When I tried to turn on the last two "writes" I got internal server errors when I attempted to access the page.

Thank you
Picture-91.png
0
 
LVL 15

Expert Comment

by:ncoo
ID: 36895780
Let me check something:

Your script is in /home/iscotest/public_html/php/order_selection_process.php

Your log files are in /home/iscotest/public_html/logs

From the error message you are trying to open /home/iscotest/public_html/php/logs

Change your opendir to:

opendir('../log/')
or
opendir('/home/iscotest/public_html/php/logs')

Can you report the errors again.

Also run the following in your script and report the results if the above has not fixed it.

var_dump(is_dir('../log/'));
var_dump(is_dir('/home/iscotest/public_html/php/logs'));
var_dump(file_exists('../log/'));
var_dump(file_exists('/home/iscotest/public_html/php/logs'));
0
 

Author Comment

by:hibbsusan
ID: 36897071
the var_dumps yield

bool(true) bool(false) bool(true) bool(false)

the path ../log/ puts the file i'm creating with the script  in the php folder (weird!)

and the path /home/iscotest/public_html/php/logs

gets the error: Warning: opendir(/home/iscotest/public_html/php/logs) [function.opendir]: failed to open dir: No such file or directory in /home/iscotest/public_html/php/order_selection_process.php on line 66

and the var_dumps don't render at all, so i guess it kills the script.
0
 

Accepted Solution

by:
hibbsusan earned 0 total points
ID: 36897124
actually i'm sorry, the directory is named "log". I changed your path (removed the s from logs) and didn't get that warning. but it still did not transfer the file correctly.
0
 

Author Closing Comment

by:hibbsusan
ID: 37089673
never figured it out.
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with PHP 13 27
PHP: Best way to scan folders and process files 10 42
Wordpress Query 5 27
JQuery Search Filter 2 40
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn how to dynamically set the form action using jQuery.

820 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