Jump to content

rename, move file


Ninjakreborn

Recommended Posts

So in it's basic form, I can do this with a file

if (isset($_POST['file1'])) {
$newname = "Some system to rename file's";
rename ($_FILES['file1']['tmp_name'], $newname);
move_uploaded_file($newname, "path");
}

something along those line's for just renaming a file that just got uploaded, then moving it to the proper directory.
Link to comment
Share on other sites

[code]
<?php

// List of our known file types
$known_file_types = array(
'image/pjpeg' => 'jpg',
'image/jpeg' => 'jpg',
'image/gif' => 'gif',
'image/bmp' => 'bmp',
'image/x-png' => 'png'
);

if(!array_key_exists($photos_uploaded['type'], $known_file_types)) {
echo "This file type is not allowed to be uploaded...";
} else {

// Fetch the photo array sent by adminconsole.php
$files_uploaded = $_FILES['upload_file']; //This is the name of your file upload field on the form

$filetype = addslashes($files_uploaded['type']);
$extension = $known_file_types[$filetype];

// Generate the filename
$filename = time();
$filename = $filename.".".$extension;

// Store the orignal file
move($files_uploaded['tmp_name'], "/uploads/".$filename);
}

?>
[/code]
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.