A php function to upload files

WBOY
Release: 2016-07-25 08:51:20
Original
1681 people have browsed it
  1. function Upload($uploaddir)
  2. {
  3. $tmp_name =$_FILES['file']['tmp_name']; // The temporary file name is obtained after the file is uploaded
  4. $name =$_FILES['file'] ['name']; // The name of the uploaded file
  5. $size =$_FILES['file']['size']; // The size of the uploaded file
  6. $type =$_FILES['file'][' type']; // Type of uploaded file
  7. $dir = $uploaddir.date("Ym");
  8. @chmod($dir,0777);//Grant permissions
  9. @is_dir($dir) or mkdir($ dir,0777);
  10. //chmod($dir,0777);//Grant permissions
  11. move_uploaded_file($_FILES['file']['tmp_name'],$dir."/".$name);
  12. $type = explode(".",$name);
  13. $type = @$type[1];
  14. $date = date("YmdHis");
  15. $rename = @rename($dir."/".$name, $dir."/".$date.".".$type);
  16. if($rename)
  17. {
  18. return $dir."/".$date.".".$type;
  19. }
  20. }
  21. Call:
  22. $image = Upload('../images/photo/');
Copy code


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!