php delete file that contains '& characters' [duplicate]












0















This question already has an answer here:




  • Delete files with special characters in filenames

    4 answers




i have string path like this "../music/Safe & Sound.mp3"



but when i tried to delete the file with PHP like this



if (!unlink($path))
{
echo "Error while deleting file";exit();
}


it shows the echo "Error while deleting file" and file failed to be deleted
i have tried to rename the file manually by removing "&" character, unlink works perfectly



so how to delete a file using unlink with special character such as "&" on its filename?










share|improve this question













marked as duplicate by Prix, Madhur Bhaiya, Vega, K.Dᴀᴠɪs, Mohammad Nov 11 at 7:25


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • How are you creating $path variable and populating it. Please add that bit of code as well.
    – Madhur Bhaiya
    Nov 11 at 5:54










  • $path="../music/Safe & Sound.mp3" i use that '..' because the file is in another folder
    – Renaldi re
    Nov 11 at 7:54


















0















This question already has an answer here:




  • Delete files with special characters in filenames

    4 answers




i have string path like this "../music/Safe & Sound.mp3"



but when i tried to delete the file with PHP like this



if (!unlink($path))
{
echo "Error while deleting file";exit();
}


it shows the echo "Error while deleting file" and file failed to be deleted
i have tried to rename the file manually by removing "&" character, unlink works perfectly



so how to delete a file using unlink with special character such as "&" on its filename?










share|improve this question













marked as duplicate by Prix, Madhur Bhaiya, Vega, K.Dᴀᴠɪs, Mohammad Nov 11 at 7:25


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • How are you creating $path variable and populating it. Please add that bit of code as well.
    – Madhur Bhaiya
    Nov 11 at 5:54










  • $path="../music/Safe & Sound.mp3" i use that '..' because the file is in another folder
    – Renaldi re
    Nov 11 at 7:54
















0












0








0








This question already has an answer here:




  • Delete files with special characters in filenames

    4 answers




i have string path like this "../music/Safe & Sound.mp3"



but when i tried to delete the file with PHP like this



if (!unlink($path))
{
echo "Error while deleting file";exit();
}


it shows the echo "Error while deleting file" and file failed to be deleted
i have tried to rename the file manually by removing "&" character, unlink works perfectly



so how to delete a file using unlink with special character such as "&" on its filename?










share|improve this question














This question already has an answer here:




  • Delete files with special characters in filenames

    4 answers




i have string path like this "../music/Safe & Sound.mp3"



but when i tried to delete the file with PHP like this



if (!unlink($path))
{
echo "Error while deleting file";exit();
}


it shows the echo "Error while deleting file" and file failed to be deleted
i have tried to rename the file manually by removing "&" character, unlink works perfectly



so how to delete a file using unlink with special character such as "&" on its filename?





This question already has an answer here:




  • Delete files with special characters in filenames

    4 answers








php file unlink






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 5:52









Renaldi re

51




51




marked as duplicate by Prix, Madhur Bhaiya, Vega, K.Dᴀᴠɪs, Mohammad Nov 11 at 7:25


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Prix, Madhur Bhaiya, Vega, K.Dᴀᴠɪs, Mohammad Nov 11 at 7:25


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • How are you creating $path variable and populating it. Please add that bit of code as well.
    – Madhur Bhaiya
    Nov 11 at 5:54










  • $path="../music/Safe & Sound.mp3" i use that '..' because the file is in another folder
    – Renaldi re
    Nov 11 at 7:54




















  • How are you creating $path variable and populating it. Please add that bit of code as well.
    – Madhur Bhaiya
    Nov 11 at 5:54










  • $path="../music/Safe & Sound.mp3" i use that '..' because the file is in another folder
    – Renaldi re
    Nov 11 at 7:54


















How are you creating $path variable and populating it. Please add that bit of code as well.
– Madhur Bhaiya
Nov 11 at 5:54




How are you creating $path variable and populating it. Please add that bit of code as well.
– Madhur Bhaiya
Nov 11 at 5:54












$path="../music/Safe & Sound.mp3" i use that '..' because the file is in another folder
– Renaldi re
Nov 11 at 7:54






$path="../music/Safe & Sound.mp3" i use that '..' because the file is in another folder
– Renaldi re
Nov 11 at 7:54














1 Answer
1






active

oldest

votes


















0














You can try by following script



$path = '../music/Safe & Sound.mp3'; /* I don't know about complete path I just want to let you know about file name */
if (!unlink($path))
{
echo "Error while deleting file";exit();
}


will escape the special character.






share|improve this answer





















  • is there any method to add that slash automatically? i have tried addslashes but it's not working
    – Renaldi re
    Nov 11 at 7:54


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You can try by following script



$path = '../music/Safe & Sound.mp3'; /* I don't know about complete path I just want to let you know about file name */
if (!unlink($path))
{
echo "Error while deleting file";exit();
}


will escape the special character.






share|improve this answer





















  • is there any method to add that slash automatically? i have tried addslashes but it's not working
    – Renaldi re
    Nov 11 at 7:54
















0














You can try by following script



$path = '../music/Safe & Sound.mp3'; /* I don't know about complete path I just want to let you know about file name */
if (!unlink($path))
{
echo "Error while deleting file";exit();
}


will escape the special character.






share|improve this answer





















  • is there any method to add that slash automatically? i have tried addslashes but it's not working
    – Renaldi re
    Nov 11 at 7:54














0












0








0






You can try by following script



$path = '../music/Safe & Sound.mp3'; /* I don't know about complete path I just want to let you know about file name */
if (!unlink($path))
{
echo "Error while deleting file";exit();
}


will escape the special character.






share|improve this answer












You can try by following script



$path = '../music/Safe & Sound.mp3'; /* I don't know about complete path I just want to let you know about file name */
if (!unlink($path))
{
echo "Error while deleting file";exit();
}


will escape the special character.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 11 at 5:56









Ayaz Shah

2,14931645




2,14931645












  • is there any method to add that slash automatically? i have tried addslashes but it's not working
    – Renaldi re
    Nov 11 at 7:54


















  • is there any method to add that slash automatically? i have tried addslashes but it's not working
    – Renaldi re
    Nov 11 at 7:54
















is there any method to add that slash automatically? i have tried addslashes but it's not working
– Renaldi re
Nov 11 at 7:54




is there any method to add that slash automatically? i have tried addslashes but it's not working
– Renaldi re
Nov 11 at 7:54



這個網誌中的熱門文章

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Xamarin.form Move up view when keyboard appear

JBPM : POST request for execute process go wrong