Lassie Posted January 22, 2007 Share Posted January 22, 2007 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 errorsWarning: 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 382Warning: readdir(): supplied argument is not a valid Directory resource in c:\program files\easyphp1-8\www\e_cart8\downloads\index.php on line 383Any help appreciated. Quote Link to comment Share on other sites More sharing options...
Cep Posted January 22, 2007 Share Posted January 22, 2007 Your problem is here,[code=php:0]$path2 = "$path.'/'.$hash";//open and read the dir $d = opendir($path);[/code]You have used $path not $path2 Quote Link to comment Share on other sites More sharing options...
Lassie Posted January 22, 2007 Author Share Posted January 22, 2007 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 382Warning: readdir(): supplied argument is not a valid Directory resource in c:\program files\easyphp1-8\www\e_cart8\downloads\index.php on line 383Thanks again, Lassie Quote Link to comment Share on other sites More sharing options...
Cep Posted January 22, 2007 Share Posted January 22, 2007 This is because you appear to be passing a hash rather than a valid directory name to the $path2 variable.What is $hash? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 22, 2007 Share Posted January 22, 2007 Another problem is that you're assigning a literal "/' in the middle of $path2:[code]<?php$path2 = "$path.'/'.$hash";?>[/code]Since $path is already "./", what you want here is:[code]<?php$path2 = $path.$hash;?>[/code]Ken Quote Link to comment Share on other sites More sharing options...
Lassie Posted January 22, 2007 Author Share Posted January 22, 2007 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. Quote Link to comment Share on other sites More sharing options...
JJohnsenDK Posted January 22, 2007 Share Posted January 22, 2007 Does the dir "3f112e23b358174d0eb3e6831a494de03f112e23b358174d0eb3e6831a494de0" exits?If it doesnt exists the opendir() function wont work. Quote Link to comment Share on other sites More sharing options...
Cep Posted January 22, 2007 Share Posted January 22, 2007 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. Quote Link to comment Share on other sites More sharing options...
Lassie Posted January 22, 2007 Author Share Posted January 22, 2007 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. Quote Link to comment Share on other sites More sharing options...
Cep Posted January 22, 2007 Share Posted January 22, 2007 try renaming the folder to something simple, retry your script with the simple name and see if you get the same error. Quote Link to comment Share on other sites More sharing options...
Lassie Posted January 22, 2007 Author Share Posted January 22, 2007 Hi GuysThanks for all the help.It works with a simple name and now works with the hash.I had doubled the no of chars so I guess 64 was a bit large.Thanks on to the next...Lassie Quote Link to comment Share on other sites More sharing options...
Lassie Posted January 23, 2007 Author Share Posted January 23, 2007 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 onan 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 :-./f6d125e0d19c484afe94dbc9ff7cfe41Warning: 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 395Warning: 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 398How to Buy a Car With Little or no credit[/code] Quote Link to comment Share on other sites More sharing options...
Cep Posted January 23, 2007 Share Posted January 23, 2007 Can I ask why you are using the word hash? Are you actually hashing a folder or file name? Quote Link to comment Share on other sites More sharing options...
Lassie Posted January 23, 2007 Author Share Posted January 23, 2007 Hi CepNo, 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 formats2.If a file has been selected go through the download process3.If file has not been read the directory and display the files in the folder in a formAs 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 Quote Link to comment Share on other sites More sharing options...
Lassie Posted January 24, 2007 Author Share Posted January 24, 2007 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 lineecho "$hash";}//set variables$path = './';$path = $path.$hash;[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.