PHP File upload and overwrite file with same name

后端 未结 4 1684
天涯浪人
天涯浪人 2020-12-14 22:23

I am making an application that allows users to upload a file in a directory via PHP.

I am having problems because it dose not allow me to overwrite files with the s

相关标签:
4条回答
  • 2020-12-14 22:53
    if (file_exists("documenti/$fileName"))
     { 
     unlink("documenti/$fileName");
    
     echo "<font face='Verdana' size='2' >Last Uploaded File has been removed from uploads folder<br>back to uploadform agian and upload your file<br>";// now your file which uploaded before was deleted from uploads folder you can open it and check if it removed or not , so no you should go back to uploadform again and import your file which will uploaded correctly 
    
    echo "<font face='Verdana' size='2' ><BR><BR><BR><a href='upform.php'>Back to upform</a><BR>";
    
     } 
    
    0 讨论(0)
  • 2020-12-14 23:00

    Maybe the script does not have the rights to overwrite? Try to change the dir to 777 and test again. If it works then, you can figure out the correct value you need

    0 讨论(0)
  • 2020-12-14 23:05

    Have you tried checking if the file exists and deleting it if it does before you move the temporary file to the permanent storage location?

    0 讨论(0)
  • 2020-12-14 23:12

    Try this (put it before upload a file)

    //checking if file exsists
    if(file_exists("documenti/$fileName")) unlink("documenti/$fileName");
    
    //Place it into your "uploads" folder mow using the move_uploaded_file() function
    move_uploaded_file($fileTmpLoc, "documenti/$fileName");
    
    0 讨论(0)
提交回复
热议问题