stevew Posted September 24, 2012 Share Posted September 24, 2012 Using xampp environment. I am trying to delete a file with the unlink function using a variable in the path. When I try to use $var I get the permissions error: <?php $var='1.jpg'; $tmpfile ='images/'?><?php echo $var; unlink($tmpfile); ?> 1.jpg Warning: unlink(images/): Permission denied in C:\xampp\htdocs\xampp\..... on line 3 However this way works fine: <?php $tmpfile ='images/2.jpg'; unlink($tmpfile); ?> 2.jpg is deleted successfully from the 'images' folder. Any help appreciated thx. Link to comment https://forums.phpfreaks.com/topic/268723-variable-in-unlink-path/ Share on other sites More sharing options...
trq Posted September 24, 2012 Share Posted September 24, 2012 Your actually trying to remove the images/ directory. Link to comment https://forums.phpfreaks.com/topic/268723-variable-in-unlink-path/#findComment-1380462 Share on other sites More sharing options...
Pikachu2000 Posted September 24, 2012 Share Posted September 24, 2012 Don't echo the variable; concatenate it. Link to comment https://forums.phpfreaks.com/topic/268723-variable-in-unlink-path/#findComment-1380463 Share on other sites More sharing options...
stevew Posted September 24, 2012 Author Share Posted September 24, 2012 Don't echo the variable; concatenate it. Thanks <?php $var='1.jpg'; $tmpfile ="images/"."$var"; unlink($tmpfile); ?> Works great. Link to comment https://forums.phpfreaks.com/topic/268723-variable-in-unlink-path/#findComment-1380474 Share on other sites More sharing options...
Christian F. Posted September 24, 2012 Share Posted September 24, 2012 The quotes around $var are completely unnecessary, and should be removed. Using them in that manner is pretty much like doing 0 + 1 + 0. Link to comment https://forums.phpfreaks.com/topic/268723-variable-in-unlink-path/#findComment-1380508 Share on other sites More sharing options...
stevew Posted September 24, 2012 Author Share Posted September 24, 2012 The quotes around $var are completely unnecessary, and should be removed. Using them in that manner is pretty much like doing 0 + 1 + 0. thanks. Link to comment https://forums.phpfreaks.com/topic/268723-variable-in-unlink-path/#findComment-1380577 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.