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 Link to comment https://forums.phpfreaks.com/topic/169781-solved-file_exists-but-filenames-have-spaces/ 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. Link to comment https://forums.phpfreaks.com/topic/169781-solved-file_exists-but-filenames-have-spaces/#findComment-895711 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. Link to comment https://forums.phpfreaks.com/topic/169781-solved-file_exists-but-filenames-have-spaces/#findComment-895719 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. Link to comment https://forums.phpfreaks.com/topic/169781-solved-file_exists-but-filenames-have-spaces/#findComment-895726 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. Link to comment https://forums.phpfreaks.com/topic/169781-solved-file_exists-but-filenames-have-spaces/#findComment-896300 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.