gijew Posted June 4, 2009 Share Posted June 4, 2009 So I've never come across this; ever. file_exists($file); Simple, right? Apparently not today. For whatever reason, it's returning false no matter what. Normally, I'd say user error (and it still may be, err, probably) but I can take the path it echo's back and pick up the file no problem. I can hard code it and it returns true. It's messing with my brain man! I'd give the breakdown of how it's being used but I don't think it's relevant here. Syntax is pretty straight forward, it's file_exists() for Jebus' sake! <?php if (file_exists($this->path . $this->path_compile . $folder . $file)) { echo 'got it'; } else { echo 'tough luck, nope: ' . $this->path . $this->path_compile . $folder . $file; } ?> The path it returns on my dev box is: "C:/wamp/www/production/clcnationwide.com/compile/439992-1244098800-56700/439992.zip" Now the folder name is auto-generated in 3 parts so here is where the error is most likely coming from. Let's just analyze the auto-gen part so hopefully we can find a solution for my brain who isn't my friend today. [part 1] - file number, it's like an internal auto-id that the document belongs to. Company thing. It stays the same. [part 2] - time stamp but only using the date and not the time ( * mktime(0,0,0,date('m'),date('d'),date('y')) * ) [part 3] - random number between 1-99999 So, I'm thinking there are a number of areas this could go wrong here but I echo out the auto-gen number through each step and it comes back the same so I don't see where the problem is. Grr. For the sake of readability I'll shut up now. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted June 4, 2009 Share Posted June 4, 2009 What's the output of this - var_dump($this->path . $this->path_compile . $folder . $file); Quote Link to comment Share on other sites More sharing options...
MadTechie Posted June 4, 2009 Share Posted June 4, 2009 little fun try this <?php if (file_exists($this->path . $this->path_compile . $folder . $file)) { echo 'got it'; } else { echo 'tough luck, nope: ' . $this->path . $this->path_compile . $folder . $file; if(is_dir($this->path)) { echo "Found: ".$this->path."<br />\n"; if(is_dir($this->path.$this->path_compile)) { echo "Found: ".$this->path.$this->path_compile."<br />\n"; if(is_dir($this->path.$this->path_compile.$folder)) { echo "Found: ".$this->path.$this->path_compile.$folder."<br />\n"; } } } } ?> Quote Link to comment Share on other sites More sharing options...
gevans Posted June 4, 2009 Share Posted June 4, 2009 little fun try this I like you're thinking, incorporating debugging into the solution!! Quote Link to comment Share on other sites More sharing options...
gijew Posted June 4, 2009 Author Share Posted June 4, 2009 var_dump() comes back with the proper path *string(83) "C:/wamp/www/production/clcnationwide.com/compile/439992-1244098800-80365/439992.zip"* And way to double, triple check there MadTechie but here are the results of your suggestion. tough luck, nope: C:/wamp/www/production/clcnationwide.com/compile/439992-1244098800-52721/439992.zip Found: C:/wamp/www/production/clcnationwide.com/ Found: C:/wamp/www/production/clcnationwide.com/compile/ Found: C:/wamp/www/production/clcnationwide.com/compile/439992-1244098800-52721/ You know, everything inside me says screw it, just write the code twice and stick it in the same method. I don't know what would be better at this point, fix it the crappy way or invest an entire day trying to fix it the right way. Lame! Such a simple function has never given me so much crap. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted June 4, 2009 Share Posted June 4, 2009 updated <?php if (file_exists($this->path . $this->path_compile . $folder . $file)) { echo 'got it'; }else{ echo 'tough luck, nope: ' . $this->path . $this->path_compile . $folder . $file; if(is_dir($this->path)) { echo "Found: ".$this->path."<br />\n"; if(is_dir($this->path.$this->path_compile)) { echo "Found: ".$this->path.$this->path_compile."<br />\n"; if(is_dir($this->path.$this->path_compile.$folder)) { echo "Found: ".$this->path.$this->path_compile.$folder."<br />\n"; $dir = $this->path.$this->path_compile.$folder; if ($dh = opendir($dir)) { while (($file2 = readdir($dh)) !== false) { if($file2 == $file) echo "<B>FOUND:</B>"; //yeah right echo "filename: $file2 : <br />\n"; } closedir($dh); } } } } } ?> EDIT: cleaned tabs in code Quote Link to comment Share on other sites More sharing options...
gijew Posted June 4, 2009 Author Share Posted June 4, 2009 Nice thoughts on opening the directory to see if it's in there if it comes back as false. That gives me a whole new headache. PHP doesn't even see the file but I browse to the folder and it's there I'm tellin' ye! This is making my noggin go in a new direction. There are two methods in use here. Method 1: create_zip(); Method 2: download_zip(); Both methods are being used inside of a download_manager() method. Method 2 is being called after the zip file is created (obviously). If I use the file_exists() function in the create_zip method after it's created, it comes back true. If I call it in the download_zip method after it IS created, it comes back false. Unless you have any suggestions on how to debug that motha I'm going to play around with the code to see if I set something improperly. It's pretty straight forward but It's quite possible I screwed something up along the way. Thank you very much for the suggestions. It was very helpful! Quote Link to comment Share on other sites More sharing options...
gijew Posted June 4, 2009 Author Share Posted June 4, 2009 So I've concluded it has something to do with the way PHP is creating the zip file. I was using the PCLZip library but the documentation is horrible and PHP5's zip library is much cleaner imo. Anyhoo, here is what I'm coming up with for those that may be interested Folder contains: 439992 Table of Contents.txt 439992.zip Both are generated by PHP. If I run file_exists() against the .txt file it comes back true. Even when I was looping through the directory using MadTechie's approach only the .txt file showed up BUT the .zip file WAS there. Has anyone come across this using PHP to create files? Kind of weird that it likes the .txt but not the .zip. I'm going to play on Google but thought I'd throw it out there in case anyone has anything to throw in besides kill yourself now Quote Link to comment Share on other sites More sharing options...
MadTechie Posted June 4, 2009 Share Posted June 4, 2009 so it doesn't list the file! Random tests just some ideas if (file_exists($this->path . $this->path_compile . $folder . $file)) { to $theFile = $this->path . $this->path_compile . $folder . $file; if (file_exists($theFile)) { Just to see, If this is running on linux, check permissions if your creating the file just before using file_exists() maybe add a sleep(2), try renaming the file via the OS to "test" and then check it.. and if all else fails call the ghost busters EDIT: just read your last post, are you sure the zip file is being closed! Quote Link to comment Share on other sites More sharing options...
gijew Posted June 4, 2009 Author Share Posted June 4, 2009 Let me laugh and quote you at the same time. Don't worry, this is freaking hilarious! EDIT: just read your last post, are you sure the zip file is being closed! Guess what the problem was? Thinking back to yesterday when I wrote this, my internal monologue was nagging at me to put $zip->close() after I finished. Right then, I looked at something else and said, I need to do that too! Guess what didn't make it back into my head? HAHA! That's why they (we) say 99.9% of the time it's user error! Thank you man, much appreciated. I will now put aside my Jimmy Jones brand Kool-Aid and put a shot of Patron silver in it's place to celebrate being DONE with this project! Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted June 4, 2009 Share Posted June 4, 2009 I know this is solved, but this may also come in handy next time you face a similar problem: http://www.php.net/manual/en/function.clearstatcache.php Quote Link to comment Share on other sites More sharing options...
gijew Posted June 4, 2009 Author Share Posted June 4, 2009 Oooh, nice. Thanks roopurt! 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.