php - Create new folder on upload based on date -
i'm new php , i've written script upload files server appended integer. now, i'm trying adjust script create new folder , name based on date when file uploaded.
i think know need do, i'm struggling syntax.
php:
if(!empty($_files)) { $temp = $_files['file']['tmp_name']; $dir_separator = directory_separator; $folder = "uploads"; $uploaddate = date("m-d-y"); if(!is_dir($uploaddate)) mkdir($uploaddate); $destination_path = dirname(__file__).$dir_separator.$folder.$dir_separator; $target_path = $destination_path.(rand(10000, 99999)."_".$_files['file']['name']); move_uploaded_file($temp, $target_path); }
any appreciated! thanks.
you should create $destination_path
variable first, create folder afterwards. like:
$uploaddate = date("m-d-y"); $destination_path = dirname(__file__).$dir_separator.$folder.$dir_separator.$uploaddate.$dir_separator; if(!is_dir($destination_path)) mkdir($destination_path);
or maybe confused $folder
, $destination_path
$target_path
;)
Comments
Post a Comment