Skip to content

Instantly share code, notes, and snippets.

@marulitua
Created February 18, 2016 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marulitua/ac1f42c3b95b86691b0b to your computer and use it in GitHub Desktop.
Save marulitua/ac1f42c3b95b86691b0b to your computer and use it in GitHub Desktop.
<?php
$dir = 'public/report';
$key_name = 'file';
if(!is_null($file = $_FILES[$key_name])) {
$now = new \DateTime('NOW');
$date_dir = sprintf("%s/%s/%s", $now->format('Y'),$now->format('m'),$now->format('d'));
$full_path_dir = sprintf("%s/%s/%s",getcwd(), $dir, $date_dir);
if(!file_exists($full_path_dir)) {
mkdir($full_path_dir, 0777, true);
}
$full_path_file = $full_path_dir.'/'.$file['name'];
move_uploaded_file($file['tmp_name'], $full_path_file);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment