cpetercarter wrote:
If you want to test whether a file exists and was uploaded via HTTP POST, you can use the is_uploaded_file() function.
Code: Select all
if (is_uploaded_file($_FILES['mailfile']['tmp_name'])) {
// do something
}
Thanks for the response guys. The above code is the condition that I am looking for.
What I want is if I click the submit botton and I did not click the browse button, it should not replace the old image path with a new one.
The reason why I asked the question above is because I tried these conditions
Code: Select all
if (isset($_POST['mailfile']) && !empty($_POST['mailfile']))
{
$newname = uniqid("whc").".jpg";
move_uploaded_file($_FILES['mailfile']['tmp_name'],
"images/$newname");
mysql_query("UPDATE table1 SET imagepath='images/$newname' WHERE id='$id'")
or die(mysql_error());
}
On the code above if a file was uploaded on a folder (for editing), the path is not inserted on sql, but the file was uploaded on a folder. And when I click the submit botton (I did not click the file browse button) it replace the old path on sql.
Code: Select all
if (isset($_FILES['mailfile']) && !empty($_FILES['mailfile']))
{
$newname = uniqid("whc").".jpg";
move_uploaded_file($_FILES['mailfile']['tmp_name'],
"images/$newname");
mysql_query("UPDATE table1 SET imagepath='images/$newname' WHERE id='$id'")
or die(mysql_error());
}
In this condition when I click the submit botton (I did not click the file browse button) it also replace the old image path with a new one on sql. But here when I click the browse button to upload a new image to replace the old one, it uploads the image on the file, it also save the path of that file to sql.