Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Zend Framework 2文件PRG删除旧文件_Php_File Upload_Zend Framework2 - Fatal编程技术网

Php Zend Framework 2文件PRG删除旧文件

Php Zend Framework 2文件PRG删除旧文件,php,file-upload,zend-framework2,Php,File Upload,Zend Framework2,我使用Zend Framework 2 fileprg上传文件。如果表单无效,它将上载一个文件,但在第二次验证后,它将再次上载具有不同名称的文件。如何删除以前以无效表单上载的旧文件?使用文件\u exists()检查文件或目录是否存在,以及 使用unlink()函数删除文件 例如: $filename = '/path/to/Images1.png'; $Message = ''; if (file_exists($filename)) { if (!unl

我使用Zend Framework 2 fileprg上传文件。如果表单无效,它将上载一个文件,但在第二次验证后,它将再次上载具有不同名称的文件。如何删除以前以无效表单上载的旧文件?

使用文件\u exists()检查文件或目录是否存在,以及 使用unlink()函数删除文件

例如:

   $filename = '/path/to/Images1.png';
    $Message = '';
    if (file_exists($filename)) {
        if (!unlink($filename)) {
            $Message = "Error deleting $filename";
        } else {
            $Message = "Deleted $filename";
        }
    } else {
        $Message = "The file $filename does not exist";
    }
     return $Message;