/**
* Delete a picture or file
* @author zhenwei Zhang <[email protected]>
* @param string $pic picture or file address
*/
function Delpic ($pic) {
if ($pic) {
$url = strlen (' http://'. $_server[' Http_host ']. ' /‘);
$ifurl = Strpos ($pic, ' uploads ');
if ($ifurl >10) {
if (file_exists (substr ($pic, $url)) {
$res = unlink (substr ($pic, $url));
if ($res) {
$return = array (' Success ' =>1, ' errors ' = ' Delete picture or file succeeded ');
} else{
$return = Array (' Success ' =>0, ' errors ' = ' operation error causing the picture or file to be deleted ');
}
}else{
$return = Array (' Success ' =>404, ' errors ' \ = ' cannot find the file or has been deleted ');
}
}else{
if (file_exists ($pic)) {
$res = unlink ($pic);
if ($res) {
$return = array (' Success ' =>1, ' errors ' = ' delete picture succeeded ');
} else{
$return = Array (' Success ' =>0, ' errors ' = ' operation error causing the picture or file to be deleted ');
}
}else{
$return = Array (' Success ' =>404, ' errors ' \ = ' cannot find the file or has been deleted ');
}
}
}else{
$return = Array (' Success ' =>404, ' errors ' = ' please send the correct picture or file address ');
}
return $return;
}
PHP Delete file (image)