Created
January 12, 2014 09:04
-
-
Save oguya/8382490 to your computer and use it in GitHub Desktop.
receive uploaded file...crud
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$storage = $_SERVER['DOCUMENT_ROOT'].'/droid/uploads/'; | |
#check uploaded file status | |
if(is_uploaded_file($_FILES['uploaded_file']['tmp_name'])){ | |
echo "\nfile successfully uploaded!\n"; | |
}else{ | |
echo "\nfile not uploaded!\n"; | |
exit; | |
} | |
foreach ($_FILES as $file_name => $file_array){ | |
echo "tmp_path: ".$file_array['tmp_name']."\n"; | |
echo "Filename: ".$file_array['name']."\n"; | |
echo "File type: ".$file_array['type']."\n"; | |
echo "File size: ".$file_array['size']."\n"; | |
//move uploaded file | |
$destination = $storage.$file_array['name']; | |
if(move_uploaded_file($file_array['tmp_name'], $destination)){ | |
echo "file successfully moved to $storage\n"; | |
// if(!is_file_empty($destination)){ | |
// rename_files($destination); | |
// } | |
}else{ | |
echo "unable to move file to $storage\n"; | |
} | |
} | |
function is_file_empty($filename){ | |
$fp = fopen($filename,'r'); | |
if($fp == NULL) | |
return true; | |
return false; | |
} | |
function rename_files($filename){ | |
$systime = shell_exec("date +%Y-%m-%d:%S"); //..unix only!!! | |
$newname = basename($filename)."-".$systime; | |
if(rename($filename, $newname)){ | |
echo "file ".basename($filename)." has been successfully renamed to ".$newname."\n"; | |
return true; | |
}else{ | |
echo "unable to rename file ".basename($filename)." to ".$newname."\n"; | |
return false; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment