PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
MiniMonty
Forum Contributor
Posts: 196 Joined: Thu Sep 03, 2009 9:09 am
Location: UK
Post
by MiniMonty » Sat Feb 25, 2012 3:47 pm
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));
}
?>
Last edited by
MiniMonty on Sun Feb 26, 2012 4:05 pm, edited 1 time in total.
MiniMonty
Forum Contributor
Posts: 196 Joined: Thu Sep 03, 2009 9:09 am
Location: UK
Post
by MiniMonty » Sat Feb 25, 2012 4:17 pm
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);
}