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. Quote 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. Quote 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. Quote 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 (edited) Don't echo the variable; concatenate it. Thanks <?php $var='1.jpg'; $tmpfile ="images/"."$var"; unlink($tmpfile); ?> Works great. Edited September 24, 2012 by stevew Quote 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. Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/268723-variable-in-unlink-path/#findComment-1380577 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.