geekpie Posted August 11, 2009 Share Posted August 11, 2009 Hi This is all CLI php loop in XP. is there a way round this problem (note space in filename before '[' ): $newfile = '"'.$path_info['filename'] . ' [Compatibility Mode].pdf"'; while (!file_exists($newfile)){ echo "Waiting for file to exist " . $newfile; } The file never exists (and it does, after it's created by PDFCreator). But if I subsitute the value in $newfile, it works, ie while (!file_exists("abc [Compatibility Mode].pdf")){ exits the loop once abc [Compatibility Mode].pdf is created Quote Link to comment Share on other sites More sharing options...
premiso Posted August 11, 2009 Share Posted August 11, 2009 $newfile = $path_info['filename'] . ' [Compatibility Mode].pdf'; It was checking for "abc [comp mode].pdf" isntead if just abc [comp mpde].pdf Replace that line and it should work. Quote Link to comment Share on other sites More sharing options...
geekpie Posted August 11, 2009 Author Share Posted August 11, 2009 But it needs the quotes because the filename has a space. Take the quotes away and you get a parse error. Quote Link to comment Share on other sites More sharing options...
premiso Posted August 11, 2009 Share Posted August 11, 2009 But it needs the quotes because the filename has a space. Take the quotes away and you get a parse error. Have you tried this theory? $newfile = $path_info['filename'] . ' [Compatibility Mode].pdf'; The above line, compared to: while (!file_exists("abc [Compatibility Mode].pdf")){ Is the exact same, except that the abc etc is stored in a variable. Now take the original line: $newfile = '"'.$path_info['filename'] . ' [Compatibility Mode].pdf"'; That is not the same, as $newfile will contain "abc [compatibility Mode].pdf" isntead of just abc [compatibility mode].pdf Try it out and see, as I think you were too quick to shoot it down. Given the statement that the manually putting the name in the while loop works, the line change that I provided should work as well. Quote Link to comment Share on other sites More sharing options...
geekpie Posted August 12, 2009 Author Share Posted August 12, 2009 Thanks: you were right to make me persist. I had become distracted into thinking I needed quotes around a filename containing a space because I did in this case in the same program: $file = '"'.$file.'"'; $output = exec('ren '.$file .' '. $newname); but that is different: I am building a dos statement. However that was enough to distract me as to how php worked. Thanks again. 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.