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.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!