Home  >  Article  >  Backend Development  >  php image upload method

php image upload method

WBOY
WBOYOriginal
2016-07-25 08:42:19952browse
  1. public function lbt() {
  2. $ajax = input::get('ajax','');
  3. if($ajax == '1'){
  4. if(!empty($_FILES)){
  5. $fileDir = public_path().'/test/';
  6. $newFile = $fileDir.$_FILES["myfile"]["name"];
  7. $info = pathinfo($newFile);
  8. $type = isset($info['extension']) ? $info['extension'] : false;
  9. $allowFiles = array('jpg', 'png', 'gif', 'mp3', 'mp4', 'wav', 'flv');
  10. if(!$type || !in_array($type, $allowFiles)){
  11. echo '文件拓展名不对';
  12. }
  13. if($_FILES["myfile"]["error"] == 0){
  14. move_uploaded_file($_FILES["myfile"]["tmp_name"], $newFile);
  15. }
  16. $data['url'] = url('test/'.$_FILES['myfile']['name']);
  17. $imgModel = new ImgModel();
  18. $imgModel->img_name = Input::get('name','');
  19. $imgModel->img_path = $_FILES['myfile']['name'];
  20. $imgModel->img_content = '';
  21. $imgModel->save();
  22. }
复制代码

图片上传, php


Statement:
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