当前位置: 首页>>代码示例>>PHP>>正文


PHP curl_file_create函数代码示例

本文整理汇总了PHP中curl_file_create函数的典型用法代码示例。如果您正苦于以下问题:PHP curl_file_create函数的具体用法?PHP curl_file_create怎么用?PHP curl_file_create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了curl_file_create函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: upload

 public function upload($filepath, $public = 0)
 {
     $filename = realpath($filepath);
     $url = 'http://storage.byte.gs/file';
     $finfo = new \finfo(FILEINFO_MIME_TYPE);
     $mimetype = $finfo->file($filename);
     $ch = curl_init($url);
     $request_headers = ["X-Auth-Token: " . $this->apiKey];
     $cfile = curl_file_create($filename, $mimetype, basename($filename));
     $data = ['file' => $cfile, 'public' => $public];
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     $result = curl_exec($ch);
     $r = curl_getinfo($ch);
     if ($r["http_code"] != 200) {
         $detais = json_decode($result, true);
         if (isset($detais["msg"])) {
             throw new \Exception($detais["msg"], 1);
         } else {
             throw new \Exception("HTTP Return " . $r["http_code"], 1);
         }
     }
     $detais = json_decode($result, true);
     $res = array();
     $res["id"] = $detais["id"];
     $res["md5"] = $detais["md5"];
     if ($public == 1) {
         $res["link"] = "http://storage.byte.gs/file/" . $res["id"] . "?md5=" . $res["md5"];
     }
     return $res;
 }
开发者ID:bytegs,项目名称:storageAPI,代码行数:33,代码来源:Storage.php

示例2: getPostField

 protected static function getPostField($path, $mimeType, $name)
 {
     if (function_exists('curl_file_create')) {
         return curl_file_create($path, $mimeType, $name);
     }
     return '@' . $path;
 }
开发者ID:Gl0dGroup,项目名称:CSICON-Publication-Tool,代码行数:7,代码来源:File.php

示例3: filePost

 /**
  * @param $url
  * @param $filename
  * @param string $fileFormName
  * @param array $params
  * @return mixed
  * 模拟表单提交文件
  */
 public static function filePost($url, $filename, $fileFormName = 'file', $params = [])
 {
     //获取文件的mime
     $finfo = finfo_open(FILEINFO_MIME);
     // 返回 mime 类型
     $mimeType = finfo_file($finfo, $filename);
     finfo_close($finfo);
     if ($mimeType) {
         $tempArr = explode(";", $mimeType);
         $mimeType = $tempArr[0];
     }
     $objFile = curl_file_create($filename, $mimeType);
     $params[$fileFormName] = $objFile;
     $curl = curl_init();
     if (stripos($url, "https://") !== FALSE) {
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
         curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
     }
     curl_setopt($curl, CURLOPT_URL, $url);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
     curl_setopt($curl, CURLOPT_TIMEOUT, self::$curlTimeOut);
     $output = curl_exec($curl);
     $errno = curl_errno($curl);
     curl_close($curl);
     return $output;
 }
开发者ID:xiaomantou88,项目名称:lib,代码行数:35,代码来源:Curl.php

示例4: testProceduralCurlFileWithMimeAndPostname

 public function testProceduralCurlFileWithMimeAndPostname()
 {
     $file = curl_file_create($this->testFilename, 'foo', 'bar');
     curl_setopt($this->handle, CURLOPT_POSTFIELDS, array('file' => $file));
     $output = curl_exec($this->handle);
     $this->assertEquals('bar|foo|6', $output);
 }
开发者ID:imnotjames,项目名称:curlfile-compat,代码行数:7,代码来源:CURLFileIntegrationTest.php

示例5: uploadToSheetHub

 /**
  * 將 $fp 上傳到 SheetHub 取得 $upload_id 待下一步
  * 
  * @param mixed $fp 
  * @access public
  * @return string $upload_id
  */
 public function uploadToSheetHub($fp, $file_type)
 {
     $sheethub_domain = getenv('SHEETHUB_DOMAIN') ?: 'sheethub.com';
     $sheethub_key = getenv('SHEETHUB_KEY');
     if (is_string($fp)) {
         $file = $fp;
     } else {
         $file = stream_get_meta_data($fp)['uri'];
     }
     $map = array('csv' => array('text/csv', 'data.csv'), 'zip' => array('text/zip', 'data.zip'), 'rar' => array('text/rar', 'data.rar'), 'xml' => array('text/xml', 'data.xml'), 'json' => array('text/json', 'data.json'), 'xls' => array('text/xls', 'data.xls'), 'xlsx' => array('text/xlsx', 'data.xlsx'));
     if (!array_key_exists($file_type, $map)) {
         throw new Exception("unknown filetype {$file_type}");
     }
     $curl = curl_init("https://{$sheethub_domain}/file/upload?access_token={$sheethub_key}");
     $cfile = curl_file_create($file, $map[$file_type][0], $map[$file_type][1]);
     curl_setopt($curl, CURLOPT_POSTFIELDS, array('file' => $cfile));
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     $content = curl_exec($curl);
     curl_close($curl);
     if (!($upload_id = json_decode($content)->data->upload_id)) {
         throw new Exception('upload failed:' . $content);
     }
     error_log("upload to sheethub done: upload_id = {$upload_id}");
     return $upload_id;
 }
开发者ID:ls-wang,项目名称:data-import-script,代码行数:32,代码来源:SheetHubTool.php

示例6: SendLabel

function SendLabel($target, $file)
{
    //$target = "http://192.168.0.205:8080/labelupload/";
    # http://php.net/manual/en/curlfile.construct.php
    // Create a CURLFile object / procedural method
    //$cfile = curl_file_create('resource/test.png','image/png','testpic'); // try adding
    $cfile = curl_file_create($file);
    // Create a CURLFile object / oop method
    #$cfile = new CURLFile('resource/test.png','image/png','testpic'); // uncomment and use if the upper procedural method is not working.
    // Assign POST data
    $imgdata = array('upl' => $cfile);
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $target);
    curl_setopt($curl, CURLOPT_USERAGENT, 'Opera/9.80 (Windows NT 6.2; Win64; x64) Presto/2.12.388 Version/12.15');
    curl_setopt($curl, CURLOPT_HTTPHEADER, array('User-Agent: Opera/9.80 (Windows NT 6.2; Win64; x64) Presto/2.12.388 Version/12.15', 'Referer: http://someaddress.tld', 'Content-Type: multipart/form-data'));
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    // stop verifying certificate
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_POST, true);
    // enable posting
    curl_setopt($curl, CURLOPT_POSTFIELDS, $imgdata);
    // post images
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    // if any redirection after upload
    $r = curl_exec($curl);
    curl_close($curl);
}
开发者ID:neohusky,项目名称:NMIS,代码行数:27,代码来源:handler.php

示例7: create

 public function create($data)
 {
     curl_file_create('./');
     if (!$this->curl) {
         return array();
     }
     if (empty($data)) {
         return false;
     }
     $this->curl->setSubmitType('post');
     $this->curl->setReturnFormat('json');
     $this->curl->initPostData();
     if (is_array($data) && count($data) > 0) {
         foreach ($data as $k => $v) {
             if (is_array($v)) {
                 $this->array_to_add($k, $v);
             } else {
                 $this->curl->addRequestData($k, $v);
             }
         }
     }
     $this->curl->addRequestData('a', 'create_tuji');
     $ret = $this->curl->request('admin/tuji_update.php');
     return $ret[0];
 }
开发者ID:h3len,项目名称:Project,代码行数:25,代码来源:tuji.class.php

示例8: UploadToBaiDu

function UploadToBaiDu($filedata, $filetype, $filename)
{
    //把保存的文件放到upload目录,因为上传还是要认文件名的
    $serverPath = "upload/" . $_FILES["file"]["name"];
    move_uploaded_file($filedata, $serverPath);
    //定义一下上传的路径
    define('BASE_PATH', str_replace('\\', '/', realpath(dirname(__FILE__) . '/')) . "/");
    //文件的全路径
    $serverFullPath = BASE_PATH . $serverPath;
    $data = array('compresstime' => '', 'filetype' => '', 'newfilesize' => '', 'Filename' => $filename, 'filewidth' => '', 'filesize' => '', 'fileheight' => '', 'Upload' => 'Submit Query', 'filedata' => curl_file_create($serverFullPath, $filetype, $filename));
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'http://image.baidu.com/pictureup/uploadshitu?fr=flash&fm=index&pos=upload');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 60);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36', 'Referer: http://img.baidu.com/img/image/stu/STUpload2.swf?v=0108', 'X-Forwarded-For: 8.8.8.8', 'Forwarded-For: 8.8.8.8', 'Origin: http://img.baidu.com', 'X-Requested-With: ShockwaveFlash/15.0.0.239'));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $html = curl_exec($ch);
    curl_close($ch);
    preg_match('/queryImageUrl=(.+?)&/', $html, $ret);
    //var_dump($ret);
    if (count($ret) === 2) {
        unlink($serverFullPath);
        return urldecode($ret[1]);
    }
    return FALSE;
}
开发者ID:vingojw,项目名称:hexoblog,代码行数:27,代码来源:index.php

示例9: startJob

 public function startJob($sourceFilePath, $targetFormat = 'txt')
 {
     // Since PHP 5.5+ CURLFile is the preferred method for uploading files
     if (function_exists('curl_file_create')) {
         $sourceFile = curl_file_create($sourceFilePath);
     } else {
         $sourceFile = '@' . realpath($sourceFilePath);
     }
     $postData = array("xlsfile" => $sourceFile, "target_format" => $targetFormat);
     $ch = curl_init();
     // Init curl
     curl_setopt($ch, CURLOPT_URL, $this->endpoint . '/jobs');
     // API endpoint
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
     curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
     // Enable the @ prefix for uploading files
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     // Return response as a string
     curl_setopt($ch, CURLOPT_USERPWD, $this->apiKey . ":");
     // Set the API key as the basic auth username
     $body = curl_exec($ch);
     if (curl_errno($ch)) {
         print_r(curl_error($ch));
     }
     curl_close($ch);
     $this->job = json_decode($body, true);
     echo "Response:\n---------\n";
     print_r($this->job);
 }
开发者ID:kawashita86,项目名称:xlsconversion,代码行数:31,代码来源:PDFConversion.php

示例10: upload_crash_report

function upload_crash_report($files, $agent)
{
    global $g;
    $post = array();
    $counter = 0;
    foreach ($files as $filename) {
        if (is_link($filename) || $filename == '/var/crash/minfree.gz' || $filename == '/var/crash/bounds.gz') {
            continue;
        }
        $post["file{$counter}"] = curl_file_create($filename, "application/x-gzip", basename($filename));
        $counter++;
    }
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://crash.opnsense.org/');
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_VERBOSE, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: multipart/form-data;'));
    $response = curl_exec($ch);
    curl_close($ch);
    return !$response;
}
开发者ID:jstrebel,项目名称:core,代码行数:26,代码来源:crash_reporter.php

示例11: getFileBody

 /**
  * @param $file
  * @param $postName
  * @param string $contentType
  * @return \CURLFile|string
  */
 protected static function getFileBody($file, $postName, $contentType = 'image/jpeg')
 {
     if (!file_exists($file)) {
         return '';
     }
     return curl_file_create($file, $contentType, $postName);
 }
开发者ID:tuanlq11,项目名称:laravel-helper,代码行数:13,代码来源:RequestHelper.php

示例12: odt_collabeditor_call_typist2

/**
 * @param string $command      name of the command
 * @param array  $data         data of the command
 *
 * @return array with the data of the reply
 */
function odt_collabeditor_call_typist2($command, $data, $filepath, $filetype, $filetitle)
{
    $fullcommand = array("command" => $command, "data" => (object) $data);
    $fullcommand_string = json_encode($fullcommand);
    $cfile = curl_file_create($filepath, $filetype, $filetitle);
    $postdata = array('message' => $fullcommand_string, 'document' => $cfile);
    $typist_control_host = elgg_get_plugin_setting('typist_control_host', 'odt_collabeditor');
    $ch = curl_init($typist_control_host . '/COMMAND2');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FAILONERROR, true);
    $output = curl_exec($ch);
    if ($output === false) {
        $output = array("success" => false, "error" => "EBADREPLY", "errorString" => curl_error($ch));
    } else {
        $output = json_decode($output);
        // TODO: decoding error handling
        if (!array_key_exists("success", $output) || $output->success && !array_key_exists("data", $output) || !$output->success && !array_key_exists("error", $output)) {
            $output = array("success" => false, "error" => "EBADREPLY", "errorString" => "Bad reply data.");
        }
    }
    // ensure dummy error string
    if (array_key_exists("error", $output) && !array_key_exists("errorString", $output)) {
        $output->errorString = "Unknown error.";
    }
    error_log('Result of typist call: ' . json_encode($output));
    curl_close($ch);
    return $output;
}
开发者ID:smellems,项目名称:odt_collabeditor,代码行数:36,代码来源:typistcom.php

示例13: addFile

 public function addFile($field_name, $absolute_filename_path)
 {
     $file_info = new \finfo(FILEINFO_MIME);
     $mime_type = $file_info->buffer(file_get_contents($absolute_filename_path));
     $mime = explode(';', $mime_type);
     $this->files[$field_name] = curl_file_create($absolute_filename_path, reset($mime), basename($absolute_filename_path));
 }
开发者ID:dekmabot,项目名称:lib-telegram-api,代码行数:7,代码来源:Transport.php

示例14: uploadSkin

function uploadSkin($inputFile)
{
    $skinFile = curl_file_create($inputFile, 'image/png', 'skin.png');
    $post = array('authenticityToken' => AUTH_TOKEN, 'model' => 'steve', 'skin' => $skinFile);
    $ch = curl_init();
    curl_setopt($ch, CURLINFO_HEADER_OUT, true);
    curl_setopt($ch, CURLOPT_URL, 'https://minecraft.net/profile/skin');
    curl_setopt($ch, CURLOPT_COOKIE, USER_COOKIE);
    curl_setopt($ch, CURLOPT_REFERER, "https://minecraft.net/profile");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: minecraft.net', 'Origin: https://minecraft.net', 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36'));
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    curl_setopt($ch, CURLOPT_COOKIESESSION, true);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $output = curl_exec($ch);
    $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if (DEBUG) {
        $headerSent = curl_getinfo($ch, CURLINFO_HEADER_OUT);
        echo "\n.\n";
        echo $headerSent;
        echo "\n.\n";
        echo $output;
        echo "\n.\n";
    }
    if ($httpcode != 302) {
        echo "Failed to upload skin\n";
        if (!DEBUG) {
            echo $output;
        }
        return false;
    }
    curl_close($ch);
    return true;
}
开发者ID:S-Toad,项目名称:MagicPlugin,代码行数:35,代码来源:uploadicons.php

示例15: upFile

 public static function upFile($local, $remote)
 {
     switch (\Config::get("services.fileuse")) {
         case "cdn":
             $data = ['file' => curl_file_create($local), 'path' => $remote, 'md5' => md5_file($local)];
             $ch = curl_init();
             curl_setopt($ch, CURLOPT_URL, \Config::get('services.fileurl.cdn.api'));
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
             $output = curl_exec($ch);
             curl_close($ch);
             if ($output == 'SUCCESS') {
                 return $remote;
             } else {
                 return false;
             }
             break;
         default:
             $save = public_path() . "/uploads" . $remote;
             $path = dirname($save);
             if (!is_dir($path)) {
                 mkdir($path, 0777, true);
             }
             if (copy($local, $save)) {
                 unlink($local);
                 return $remote;
             } else {
                 return false;
             }
             break;
     }
 }
开发者ID:9618211,项目名称:php-laravel-rbac,代码行数:33,代码来源:Tools.php


注:本文中的curl_file_create函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。