Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.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替换现有的图像文件_Php_Html_Database - Fatal编程技术网

如何使用PHP替换现有的图像文件

如何使用PHP替换现有的图像文件,php,html,database,Php,Html,Database,当我上载名为boy.png的图像文件时,它不会使用move\u uploaded\u file()替换现有的boy.png 第二个boy.png是一个不同的图像 如果文件已经存在,如何使用PHP上载和替换该文件?您可以通过这种方式首先检查同名文件是否已经存在?如果存在,则删除旧版本并上载新版本。让我们这样试试- //checking if file with same name already exists if(file_exists("pathtofile/boy.png")) unlink

当我上载名为
boy.png
的图像文件时,它不会使用
move\u uploaded\u file()
替换现有的
boy.png

第二个
boy.png
是一个不同的图像


如果文件已经存在,如何使用PHP上载和替换该文件?

您可以通过这种方式首先检查同名文件是否已经存在?如果存在,则删除旧版本并上载新版本。让我们这样试试-

//checking if file with same name already exists
if(file_exists("pathtofile/boy.png")) unlink("pathtofile/boy.png");

//upload file now using the move_uploaded_file()
move_uploaded_file($fileLocTemporary, "pathtofile/boy.png"); # change as per your temp location