php delete file that contains '& characters' [duplicate]
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?
php file unlink
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.
add a comment |
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?
php file unlink
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
add a comment |
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?
php file unlink
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
php file unlink
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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.
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
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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