Jump to content

fopen with space in windows path


ober
 Share

Recommended Posts

I'm trying to create a simple data dump to a text file.  It was all working fine and now fopen doesn't like my relative paths.  So I'm using an absolute path to the file:

 

C:\\Program Files\\FDS\\DTManage\\Web\\DTM\\php\\DTBill\\sources\\snapshot\\snapshot.txt

 

But fopen keeps saying it can't open the file.  It's acting like it isn't there.

 

$path_parts = pathinfo(__FILE__); 
$filename = str_replace('\\', '\\\\', $path_parts['dirname'])."\\\\snapshot.txt";

if (!$handle = fopen($filename, 'w')) {
     echo "Cannot open file ($filename)";
}

 

Can someone tell me why this isn't working?  :wtf:

Link to comment
Share on other sites

Ober,

 

Do you need to escape your backslashes in the str_replace() if they're in single quotes?  Personally, I'd replace them with forward slashes.

 

Are you getting any errors output?  This should be simple to fix, but I don't have my windows server running at the moment to test.

 

Regards

Huggie

Link to comment
Share on other sites

Well the path returned by pathinfo uses backslashes, so I have to use backslashes for the rest unless I replace them all with forward slashes, which I don't think I've tried.  And my editor doesn't like it when I don't escape them, so I assumed I had to (PHP Designer 7).

 

This is the error:

Warning: fopen(C:\\Program Files\\FDS\\DTManage\\Web\\DTM\\php\\DTBill\\sources\\snapshot\\snapshot.txt): failed to open stream: Permission denied in C:\Program Files\FDS\DTManage\Web\DTM\php\DTBill\sources\snapshot\createExport.php on line 5 Cannot open file (C:\\Program Files\\FDS\\DTManage\\Web\\DTM\\php\\DTBill\\sources\\snapshot\\snapshot.txt) Warning: fclose(): supplied argument is not a valid stream resource in C:\Program Files\FDS\DTManage\Web\DTM\php\DTBill\sources\snapshot\createExport.php on line 32
Link to comment
Share on other sites

OK, I have access to my Windows box now.  I've just tested your code on a directory with spaces and it works fine.

 

Your error indicates a permissions problem.  Check the permissions first, if that doesn't work, use MMC to check that the file handle isn't still open.

 

Regards

Huggie

Link to comment
Share on other sites

You're getting a "Permission Denied" error message. You are using Windows Vista which does not allow general users to write files into the "Program Files" directory or any of it's sub-directories. Write your file to a different directory.

 

It always helps to give the exact error message in your initial post.

 

Ken

Link to comment
Share on other sites

It's Windows Server 2003.  And I'll say it again, this worked when I initially wrote it and the location of the file hasn't changed and the server hasn't changed.

 

And it's not read-only (the file).  And the user (as far as the webserver) hasn't changed either.

Link to comment
Share on other sites

Good Question...

 

I'm not sure if it will work on Server 2003.  Here's my instructions for XP.

 

Start >> Run

Type mmc and click Ok.

File >> Add/Remove Snap In >> Add

Select 'Computer Management' >> Add >> Finish >> Close >> OK

 

This should now show you the MMC with your local computer.

 

If this works then let me know.

 

Huggie

Link to comment
Share on other sites

This thread is more than a year old.

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.

 Share

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