Heim  >  Artikel  >  Backend-Entwicklung  >  php图片上传方法

php图片上传方法

WBOY
WBOYOriginal
2016-07-25 08:42:19916Durchsuche
  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


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn