image upload - Rename photo completely before uploading - php -


i'd totally rename file before uploads. other posts i've found on here seem append beginning or end of file name make unique, want wipe name , rename it.

input: anyoldfilename.jpg output: thisnameexactly.jpg

the following function i'm working uploads doesn't rename file. name should $newfilename, i've created in function:

$target = "../files/photos/" $target = $target . basename( $_files['photo']['name']);  //find file extension of photo $newfilename = "thisnameexactly"; $ext = end(explode('.', $_files['photo']['name'])); $newfilename = $newfilename . "." . $ext;  if(move_uploaded_file($_files['photo']['tmp_name'], $target)){    echo "image uploaded"; } else {    echo "sorry, there problem uploading file."; } 

how can modify renames file entirely?

$target = $target . basename( $_files['photo']['name']);  

you have on top, move as

$target = "../files/photos/"  //find file extension of photo $newfilename = "thisnameexactly"; $ext = end(explode('.', $_files['photo']['name'])); $newfilename = $newfilename . "." . $ext;  $target = $target . $newfilename;  if(move_uploaded_file($_files['photo']['tmp_name'], $target)){    echo "image uploaded"; } else {    echo "sorry, there problem uploading file."; } 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -