Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 411
  • Last Modified:

php opendir directory navigation

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
hibbsusan
Asked:
hibbsusan
  • 9
  • 3
1 Solution
 
ncooCommented:
It could be an issue with file permissions.

Have you checked them?

Does PHP have permission to that directory?
0
 
jaxbrianCommented:
have you tried to put ../log

if you needed to go up two directories it would be ../../
0
 
hibbsusanAuthor Commented:
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
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
hibbsusanAuthor Commented:
../log

yes.
0
 
hibbsusanAuthor Commented:
but ../log doesn't work either
0
 
ncooCommented:
What error messages does PHP give when trying to access?

error_reporting(0);
0
 
hibbsusanAuthor Commented:
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
 
hibbsusanAuthor Commented:
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
 
hibbsusanAuthor Commented:
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
 
ncooCommented:
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
 
hibbsusanAuthor Commented:
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
 
hibbsusanAuthor Commented:
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
 
hibbsusanAuthor Commented:
never figured it out.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

  • 9
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now