简体   繁体   中英

unlink() doesn't work with double backslashes

I'm trying to delete a file this way:

define('DESTINATION_FOLDER','c:\temp\\');  
unlink(DESTINATION_FOLDER.$dest_filename);

And $dest_filename is something like this: 2jfioj23488hgh83hr.zip

But this doesn't work. When I put the path in a variable and echo it, it prints:

c:\temp\2jfioj23488hgh83hr.zip

Then I copy/paste it in unlink():

unlink('c:\temp\2jfioj23488hgh83hr.zip')

And it works. I think the problem is with the double backslashes. But how should I define the path without using the double backslashes? I don't know why it doesn't work. The line just above this code is:

copy((DESTINATION_FOLDER.$dest_filename),($extract.'\\'.$dest_filename));

And it works fine, but unlink doesn't work with the same syntax.

Putting my comment as an answer to the question

Try using forward slashes instead of backslash :)

如果由于某种原因必须使用反斜杠,则需要使用c:\\\\而不是c:\\

define('DESTINATION_FOLDER','c:\\\\temp\\\\');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM