Skip to content

Instantly share code, notes, and snippets.

@marulitua
Created March 10, 2016 07:02
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/921b9f936b83ae7b1712 to your computer and use it in GitHub Desktop.
Save marulitua/921b9f936b83ae7b1712 to your computer and use it in GitHub Desktop.
<?php
$dir = '/reports';
$key_name = 'file';
$key_imei = 'imei';
if(isset($_FILES[$key_name]) && !is_null($file = $_FILES[$key_name]) && !is_null($imei = $_POST[$key_imei])) {
$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);
}
$file_name = sprintf("%s_%s.zip", $imei, $now->getTimeStamp());
$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