如何使用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