Page 1 of 1

Trouble renaming... (SOLVED)

Posted: Sat Feb 25, 2012 3:47 pm
by MiniMonty
Hi all,

having a little trouble with an "upload and rename" script.

Code here - any help much appreciated.
Monty

Code: Select all

<?php
$ext = pathinfo($filename, PATHINFO_EXTENSION);
	// strip the file extension
	$file_without_ext = substr($filename, 0, -4);
	// set random newname (timestamp)
	$randFilename = uniqid('img_');
	$newFilename = $randFilename.".".$ext;
	if ($_FILES['Filedata']['name']) {
		move_uploaded_file($_FILES['Filedata']['tmp_name'], '../news/images/' . basename($_FILES['Filedata']['name'],$newFilename));
	}
?>

Re: Trouble renaming...

Posted: Sat Feb 25, 2012 4:17 pm
by MiniMonty
DOH - solved....

Code: Select all

	$ext = pathinfo($filename, PATHINFO_EXTENSION);
	// strip the file extension
	$file_without_ext = substr($filename, 0, -4);
	// rename file with random (timestamp)
	$randFilename = uniqid('img_');
	$newFilename = $randFilename.".".$ext;
	if ($_FILES['Filedata']['name']) {
		move_uploaded_file($_FILES['Filedata']['tmp_name'], '../news/images/' . $newFilename);
	}