Jump to content

open and read directory errors


Lassie

Recommended Posts

I need to construct a directory path from 2 variables and then open and read the directory.
I get invalid arguement errors.
My code is:
[code]
//set variables
$hash = '3f112e23b358174d0eb3e6831a494de03f112e23b358174d0eb3e6831a494de0';
$path = './';
//combine the path

$path2 = "$path.'/'.$hash";
//open and read the dir
$d = opendir($path);
while (false !== ($file = readdir($d))) {//code goes on to get file attributes etc
if ($file != "." && $file != "..") {
[/code]
The errors
Warning: opendir(C:/Program Files/EasyPHP1-8/www/e_cart8/Downloads/3f112e23b358174d0eb3e6831a494de03f112e23b358174d0eb3e6831a494de0/): failed to open dir: Invalid argument in c:\program files\easyphp1-8\www\e_cart8\downloads\index.php on line 382

Warning: readdir(): supplied argument is not a valid Directory resource in c:\program files\easyphp1-8\www\e_cart8\downloads\index.php on line 383

Any help appreciated.
Link to comment
Share on other sites

Hi cep,
Thanks. i changed the code to path2 and I still get the errors.
If i leave it as open dir $path that works,but within that dir I have a hash folder I am trying to open, hence the need to combine the path.
If u have any further thougts I would be grateful.
the code now reads
[code]
set the variables
$hash = '3f112e23b358174d0eb3e6831a494de03f112e23b358174d0eb3e6831a494de0';

$path = './';
$path2 = "$path.'/'.$hash";
//open and read combined path
$d = opendir($path2);
while (false !== ($file = readdir($d))) {
if ($file != "." && $file != "..") {

[/code]
errorsWarning: opendir(./.'/'.3f112e23b358174d0eb3e6831a494de03f112e23b358174d0eb3e6831a494de0): failed to open dir: Invalid argument in c:\program files\easyphp1-8\www\e_cart8\downloads\index.php on line 382

Warning: readdir(): supplied argument is not a valid Directory resource in c:\program files\easyphp1-8\www\e_cart8\downloads\index.php on line 383

Thanks again, Lassie
Link to comment
Share on other sites

Hi Ken,
Thanksfor that.Tried it and get the same errors.
If i set the $path to something like $path = './test/'; it works fine, but not with the hash var.
To answer cep the hash is a folder that holds filenames of items a customer has chosen to download.
The purpose of the hash folder is to have identification and validation mechanism for picking up on an email link the customer clicks to collect the purchase.
Link to comment
Share on other sites

Exactly my point I do not believe you can have a directory of that name length I would check to see that the name you have given is the name of an actual directory, the one thing that concerns me is that your probably trying to use a hashed version of the folder name as you have called the variable $hash.
Link to comment
Share on other sites

Hi guys,
Thanks for your responses.
The dir is made and does exist in the dir download designated to hold these temp files.
Would it be better to use a var based on text such as the name.
If so how could i make it unique?
Could I add a random string of chars say, like a salt?
I will check the hash again to see if I am doubling it up soemwhere.
Link to comment
Share on other sites

Thanks for the help I got on this problem yesteraday. I thought it was solved but I was wrong.
To recap I need to construct a dir path with 2 variables.$path and $hash
$path is a download dir that holds temp folders created with a hash id. This is 32 chars.
The purpose of the hash folder is to have identification and validation mechanism for picking up on
an email link the customer clicks to collect the purchase.
The $hash folder holds a customers selected products ie filenames.
The problem is reading the hash file and getting the file attributes.
The program for the download is located in the $path(download) folder.
If i set the $path to something like $path = './test/'; it works fine, but not with the hash var.
The hash folders do exist.

[code]
<?
if(isset($_POST['submit_btn']))
{
$hash = $_POST['hash'];
echo "$hash";
}
//set variables
$path = './';
$path2 = $path.$hash;
# Read current directory.
#------------------------
$d = opendir($path2);
while (false !== ($file = readdir($d))) {
if ($file != "." && $file != "..") {
echo"$path2";
# Get all the file attributes.
#-----------------------------
$size = filesize("$path2$file");
      $type = filetype("$path2$file");
      $ext = strrchr("$path2$file",'.');
$modified = stat("$path2$file");
$displayname = str_replace (strrchr ($file, "."), "", $file);
echo"$displayname";

errors :-
./f6d125e0d19c484afe94dbc9ff7cfe41
Warning: filesize(): Stat failed for ./f6d125e0d19c484afe94dbc9ff7cfe41How to Buy a Car With Little or no credit.pdf (errno=2 - No such file or directory) in c:\program files\easyphp1-8\www\e_cart8\downloads\index.php on line 395

Warning: stat(): Stat failed for ./f6d125e0d19c484afe94dbc9ff7cfe41How to Buy a Car With Little or no credit.pdf (errno=2 - No such file or directory) in c:\program files\easyphp1-8\www\e_cart8\downloads\index.php on line 398
How to Buy a Car With Little or no credit

[/code]
Link to comment
Share on other sites

Hi Cep
No, I am not hash a file or folder I'm creating a temp file to store filenames in.
I called it hash to remind myself what i had done.It is made up of an email address and a random number.
The hash folder number (loose inteprtation) is stored and sent as pur identifier in a link in an email confirming purchase.
When the link is clicked the pur id ( the hash )is attached and then compared with the hash records.
If theres a match then folder is read with the intent of showing a small table with the product(s) indentified.
Clicking on the link shows the download dialogue alert, to save or open.
The download program is quite long and one I am adapting to my purpose (hopefully) and therefore I have not posted the whole thing.
Broadly it is structured thus:
1.Set up variables for the path and display formats
2.If a file has been selected go through the download process
3.If file has not been read the directory and display the files in the folder in a form

As I said previously $path = "./test/"; works fine. I just need to get my variable there and with a trailing / it seems.
Thanks for you interest.
Lassie
Link to comment
Share on other sites

Hi cep,
Just to let u know i did the following and it works. I now need to make the hash value persit since once the link(s) are clicked for the download it goes back to the start and the value of  $hash is lost.
I will try a session varaible.
Additionally the script requires globals on so I need to fix that as well.
Thanks again for your help.
[code]
if(isset($_POST['submit_btn']))
{
$hash = $_POST['hash'];
$hash = $hash."/";//new line
echo "$hash";
}
//set variables
$path = './';
$path = $path.$hash;
[/code]
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.