0

I want to change image name with current time stamp in php. My code are below :

$logo = basename($_FILES['file']['name']);

$logo = image1.jpg
move_uploaded_file($_FILES['file']['tmp_name'], '../timeTableImg/' . $_FILES['file']['name']);

i get image name in $logo. But Actually i want

$logo = 1484900616.jpg 

move_uploaded_file($_FILES['file']['tmp_name'], '../timeTableImg/' . $_FILES['file']['name']);

file name may be dynamic. its may be jpg , png, jpeg. Also want to move file with new name.

Meena patel
  • 149
  • 1
  • 4
  • 16

2 Answers2

0

Use move_uploaded_file function.

Example:

$file_path = "uploads/";   
$newfile = date('m-d-Y_H:i:s')'.jpg';
$filename = $file_path.$newfile;
if(!file_exists($filename))
{
    if(move_uploaded_file($_FILES['file']['tmp_name'],$filename))
    {
    // Other codes
    }
}
else
{
    echo 'file already exists';
}
-1

Try this.

$path = $_FILES['file']['name']; 
$ext = pathinfo($path, PATHINFO_EXTENSION);
$logo = time().'.'.$ext;

And to use the new name. put this.

move_uploaded_file($_FILES['file']['tmp_name'], '../timeTableImg/' . $logo);
Mark Vincent Manjac
  • 507
  • 1
  • 6
  • 27