Jump to content

[SOLVED] file_exists: but filenames have spaces


geekpie

Recommended Posts

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
Share on other sites

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
Share on other sites

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
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.