November 6, 2012
File replace in upload in php
Question by Mervyn
I would like to delete a file that is already exists and add the new one in the same folder.
I have taken the tmp name added it in a session. Deleted the existing already but it not movin in the new one.
<?php session_start(); $files = $_SESSION['Already']; $tmp=$_SESSION['PATH']; unlink('../upload/'.$files); $to="../upload/".$files; move_uploaded_file($tmp,$to); ?>
Answer by Starx
Try replacing the files. If the files name are exactly same, you don’t need to unlink them. Just using
move_uploaded_file() will do.
Its important to know what is causing the error. Check your server
error_logs for such informations.