<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                **readfile和file_put_contents下載遠程圖片到本地** ``` <?php function download_image($pic_url) { $time = time(); $pic_local_path = dirname(__FILE__) . '/cache'; $pic_local = $pic_local_path . '/' . $time; if (!file_exists($pic_local_path)) { mkdir($pic_local_path, 0777); @chmod($pic_local_path, 0777); } ob_start(); //打開輸出 readfile($pic_url); //輸出圖片文件 $img = ob_get_contents(); //得到瀏覽器輸出 ob_end_clean(); //清除輸出并關閉 file_put_contents($pic_local, $img); return $pic_local; } ``` **curl下載遠程圖片到本地** ``` <?php $ch = curl_init(); $fp=fopen('./girl.jpg', 'w'); curl_setopt($ch, CURLOPT_URL, "https://img02.sogoucdn.com/app/a/100520091/20181209114105"); curl_setopt($ch, CURLOPT_FAILONERROR, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 100); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_FILE, $fp); $output = curl_exec($ch); $info = curl_getinfo($ch); $error = curl_error($ch); fclose($fp); $size = filesize("./girl.jpg"); if ($size != $info['size_download']) { echo "下載失敗"; echo $error; } else { echo "下載成功"; } curl_close($ch); ``` ``` /** * 下載遠程圖片到本地 * * @param string $url 遠程文件地址 * @param string $filename 保存后的文件名(為空時則為隨機生成的文件名,否則為原文件名) * @param array $fileType 允許的文件類型 * @param string $dirName 文件保存的路徑(路徑其余部分根據時間系統自動生成) * @param int $type 遠程獲取文件的方式 * @return json 返回文件名、文件的保存路徑 * @author blog.snsgou.com */ function download_image($url, $fileName = '', $dirName, $fileType = array('jpg', 'gif', 'png'), $type = 1) { if ($url == '') { return false; } // 獲取文件原文件名 $defaultFileName = basename($url); // 獲取文件類型 $suffix = substr(strrchr($url, '.'), 1); if (!in_array($suffix, $fileType)) { return false; } // 設置保存后的文件名 $fileName = $fileName == '' ? time() . rand(0, 9) . '.' . $suffix : $defaultFileName; // 獲取遠程文件資源 if ($type) { $ch = curl_init(); $timeout = 30; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $file = curl_exec($ch); curl_close($ch); } else { ob_start(); readfile($url); $file = ob_get_contents(); ob_end_clean(); } // 設置文件保存路徑 //$dirName = $dirName . '/' . date('Y', time()) . '/' . date('m', time()) . '/' . date('d', time()); $dirName = $dirName . '/' . date('Ym', time()); if (!file_exists($dirName)) { mkdir($dirName, 0777, true); } // 保存文件 $res = fopen($dirName . '/' . $fileName, 'a'); fwrite($res, $file); fclose($res); return array( 'fileName' => $fileName, 'saveDir' => $dirName ); } ``` PHP讀寫大 二進制 文件 不必申請很大內存(fopen、fread、fwrite、fclose) ``` <?php /** * 讀寫大二進制文件,不必申請很大內存 * 只有讀取到內容才創建文件 * 保證目錄可寫 * * @param string $srcPath 源文件路徑 * @param string $dstPath 目標文件路徑 * @return bool */ function fetch_big_file($srcPath, $dstPath) { set_time_limit(0); // 設置腳本執行時間無限長 if (!$fpSrc = fopen($srcPath, "rb")) { return false; } $isWriteFileOpen = false; // 寫文件 是否已打開? do { $data = fread($fpSrc, 8192); // 每次讀取 8*1024個字節 if (!$data) { break; } else if (!$isWriteFileOpen) { // 第一次讀取文件,并且有內容,才創建文件 $fpDst = fopen($dstPath, "wb"); $isWriteFileOpen = true; fwrite($fpDst, $data); } else { // 寫入 fwrite($fpDst, $data); } } while (true); fclose($fpSrc); fclose($fpDst); return true; } $srcPath = 'd:/big.pdf'; $dstPath = 'Z:/big.pdf'; fetch_big_file($srcPath, $dstPath); echo 'success'; ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看