phpファイルのダウンロード

3564 ワード

1.入力パラメータは、function内の配列のkeyとして使用されます。
function test2($name){
    $ar = (object) array(
     $name => 1,
     "image_id"=>1234
    );
    echo $ar->$name;
}
//  host_id value
test2(host_id);
2.ファイルダウンロードdest_pathは'/tmp/imags/raw_イマジネーション.jpg’イマージュ[u]srcは写真のhttpルートです。
//      ,     ,     
            if (file_exists($dest_path)) {
                unlink($dest_path);
            }
            //       
            $f_output = fopen($dest_path, 'a');
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $image_src);
            curl_setopt($ch, CURLOPT_FILE, $f_output);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
            curl_setopt($ch, CURLOPT_LOW_SPEED_LIMIT, 2);
            curl_setopt($ch, CURLOPT_LOW_SPEED_TIME, 60);

            $result = curl_exec($ch);
            curl_close($ch);
            fclose($f_output);
            if ($result) {
                break;
            }
3.ファイルアップロードurlはアップロードパスです。
$ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_VERBOSE, true);
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, array('file' => $bs64));
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

            $res = curl_exec($ch);
            curl_close($ch); 
            }