原生檔案上傳

來源:互聯網
上載者:User

標籤:style   blog   io   ar   color   sp   on   檔案   div   

如果你的項目對上傳不需要很強大的上傳,就可以採用下面的函數,進行傳輸!

public function GrabImage($data) {        $php_path = dirname(__FILE__) . ‘/‘;        $php_url = dirname($_SERVER[‘PHP_SELF‘]) . ‘/‘;        //檔案儲存目錄路徑        $save_path = $php_path . ‘../../../upload/image/leavemessagimg/‘;        //檔案儲存目錄URL        $save_url = $php_url . ‘../../../upload/image/leavemessagimg/‘;        //新檔案名稱        $file_name = $_FILES[‘uploadfiles‘][‘name‘];        $temp_arr = explode(".", $file_name);        $file_ext = array_pop($temp_arr);        $file_ext = trim($file_ext);        $file_ext = strtolower($file_ext);        $new_file_name = date("YmdHis") . ‘_‘ . rand(10000, 99999) . ‘.‘ . $file_ext;        $file_path = $save_path . $new_file_name;        if ((($data[‘uploadfiles‘]["type"] == "image/gif")        || ($data[‘uploadfiles‘]["type"] == "image/jpeg")        || ($data[‘uploadfiles‘]["type"] == "image/pjpeg"))        && ($data[‘uploadfiles‘]["size"] < 1000000))          {          if ($data[‘uploadfiles‘]["error"] > 0)            {            echo "Return Code: " . $data[‘uploadfiles‘]["error"] . "<br />";            }          else            {            if (file_exists($file_path))              {              echo $data[‘uploadfiles‘]["name"] . " already exists. ";              }            else              {                  if(move_uploaded_file($data[‘uploadfiles‘]["tmp_name"],$file_path)==false)                  {                      echo ‘上傳失敗‘;exit;                  }                  @chmod($file_path, 0644);                  //儲存圖片路徑                  $file_url = ‘/upload/image/leavemessagimg/‘. $new_file_name;              }            }          }        else          {          echo "Invalid file";          }          return $file_url;    }

 

原生檔案上傳

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.