Reputation: 8317
For some reasons I'd like to have some data stored in a removable storage (namely USB-stick). I have the WAMP package installed and it has its .../www/ folder where scripts can do edit files etc. I'd like my server to be able to read/write files from/to another folder which is in the removable storage.
I've tried already relative paths and can see that file_put_contents
works with folders outside www/
(potentially a cause of security issues..). However, my removable storage is the E:\
drive in Windows, so to write there I need to use an absolute path. I've tried to use the Windows absolute path directly like
file_put_contents("C:\existing\path\copied\from\explorer\new_file.txt","Stage 3, successfully written");
(first on C:\
to distinct if a fail of writing occurs because the path doesn't work or because writing to another storage is forbidden) and that failed.
So, is it possible at all? What should I use instead of the path as it is written in Windows explorer? Or may be I should use another function to achieve this? Or give that path an some alias using Apache config?
The point is the removable storage should be safely removable at any time, except for the moment of reading/writing.
PS thanks to ÁlvaroGonzález, I've figured that I just forgot to escape the \
symbols in my absolute path, copied from explorer, that's why writing to it directly failed.
Upvotes: 0
Views: 4665
Reputation: 146440
Just a tiny syntax problem:
var_dump("C:\existing\path\copied\from\explorer\new_file.txt");
... prints something like:
string(46) "C:xisting\path\copiedromxplorer
ew_file.txt"
... because you've been unlucky enough to use a double-quoted string and existing escape sequences:
\e
escape (hex 1B) \f
formfeed (hex 0C)\n
newline (hex 0A)Some valid alternatives:
'C:\existing\path\copied\from\explorer\new_file.txt'
"C:\\existing\\path\\copied\\from\\explorer\\new_file.txt"
"C:/existing/path/copied/from/explorer/new_file.txt"
Upvotes: 1
Reputation: 471
Create a separate directory in your WAMP /www/ directory and make a symbolic link to wherever you need. Some good reading: http://www.tuxera.com/community/ntfs-3g-advanced/junction-points-and-symbolic-links/
Upvotes: 1