I want to let users upload Images. The file gets re-named (by adding the time() to the current name) and then moved to my Images/ folder. I then reference the name uploaded into the database table in my html/php code. The images won’t appear because the name in the table is different from the actual file name. The image name needs to be changed in-case two users ever upload a file with the same name. How can I apply the time() name change to both the file name in the table and the actual file name so the images appear. Here is my code:
if (!empty($_FILES['picture']))
{
$pic= $_FILES['picture']['name'];
$target= GW_UPLOADPATH . time() . $pic;
if (move_uploaded_file($_FILES['picture']['tmp_name'], $target))
{
$query= "INSERT INTO posts (user_id, story, picture) VALUES
('$user_id', '$story', '$pic')";
mysqli_query($connect, $query);
header( 'Location: profile.php' );
}
}
The picture name in the table is just ball.jpg and the actual file might be 18292018ball.jpg.
Try this