having a little trouble with upload and rename.
I've got this far:
Code: Select all
$target_path = "images/";
$filename = ( $_FILES['picture']['name']);
// get the file extension
$ext = pathinfo($filename, PATHINFO_EXTENSION);
// strip the extension (assumes .gif, .jpg, .png etc i.e. 3 letters after a dot
substr($filename, 0, -4);
// rename file with random (timestamp)
$randFilename = uniqid("img_");
$newFilename = $randFilename.".".$ext;
// put file on the server
$target_path = $target_path . basename( $_FILES['picture']['name']);
if(move_uploaded_file($_FILES['picture']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['picture']['name']).
" has been uploaded as " . $newFilename;
} else{
echo "No Pictures uploaded";
}
All and any help much appreciated
Monty