Page 1 of 1
file upload & file renaming
Posted: Mon May 29, 2006 5:19 am
by ggrrr
Posted: Mon May 29, 2006 5:26 am
by someberry
What is your code at the moment, it's kinda hard to just guess the problem, especially from your description

Posted: Mon May 29, 2006 5:32 am
by $phpNut
rename it in the copy or move_uploaded_file
i.e.
Code: Select all
$tempFile = $_FILES['name of file object']['tmp_name'];
$uploadDir = "./uploads/";
$fileExtension = pathinfo($_FILES['name of file object']['tmp_name'], PATHINFO_EXTENSION)
$newFilename = date("d-m-Y_H:i") . $fileExtension;
copy ($tempFile, $uploadDir . $newFilename);
// or
move_uploaded_file ($tempFile, $uploadDir . $newFilename);
in theory, should work, I haven't tested it though. I use that sort of setup and works for me.
ggrrr
Posted: Mon May 29, 2006 5:38 am
by ggrrr
twigletmac | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
wow 2 replies people acctuall care awww isnt that nice
thankz if you want to see my code so far its pretty simple but it works
Code: Select all
<?php
$target_path = "uploads/";
/* Add the original filename to our target path. Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$_FILES['uploadedfile']['tmp_name'];
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
just to explain bit more i wanted something to add in so the files that are uploaded into the folder are renamed when they are put on the server.
thankz for the script ill see if it werks or if i fail (i will most likely fail) but that wont stop me
merry christmas from ggrrr
twigletmac | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Mon May 29, 2006 5:46 am
by $phpNut
just change the target path, it'll move it to a new filename.
Code: Select all
// Get file extension so there shouldn't be any unexpected errors
$fileExtension = pathinfo($_FILES['name of file object']['tmp_name'], PATHINFO_EXTENSION);
// Include the new name in the target_path variable
$target_path = $target_path . date("d-m-Y_H:i") . "." . $fileExtension;
// Example $target_path "uploads/28-05-2006_11:15.png"
*$target_path edited to include a '.' between the name and extension (forgot to in the last example).
YEY
Posted: Mon May 29, 2006 6:24 am
by ggrrr