$file = new CurlFile($name); } } curl_setopt($ch, CURLOPT_POSTFIELDS, array("file" => $file)); var_dump(curl_exec($ch)); } include 'server.inc'; $host = curl_cli_server_start(); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "{$host}/get.php?test=file"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); testcurl($ch, __DIR__ . '/curl_testdata1.txt'); testcurl($ch, __DIR__ . '/curl_testdata1.txt', 'text/plain'); testcurl($ch, __DIR__ . '/curl_testdata1.txt', '', 'foo.txt'); testcurl($ch, __DIR__ . '/curl_testdata1.txt', 'text/plain', 'foo.txt'); $file = new CurlFile(__DIR__ . '/curl_testdata1.txt'); $file->setMimeType('text/plain'); var_dump($file->getMimeType()); var_dump($file->getFilename()); curl_setopt($ch, CURLOPT_POSTFIELDS, array("file" => $file)); var_dump(curl_exec($ch)); $file = curl_file_create(__DIR__ . '/curl_testdata1.txt'); $file->setPostFilename('foo.txt'); var_dump($file->getPostFilename()); curl_setopt($ch, CURLOPT_POSTFIELDS, array("file" => $file)); var_dump(curl_exec($ch)); $params = array('file' => '@' . __DIR__ . '/curl_testdata1.txt'); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); var_dump(curl_exec($ch)); curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true); $params = array('file' => '@' . __DIR__ . '/curl_testdata1.txt');
$rejected_due_to_hold = false; // Let's make sure the API key and username are set to match current config $xml = new SimpleXMLElement(file_get_contents($filename)); if (in_array($xml->variables->formname, $api_key_required)) { $rejected_due_to_acl = !$api_passed; $xml->variables->api_key = $Config['api_key']; } file_put_contents($filename, $xml->asXML()); if (isset($xml->variables->formname) && $xml->variables->formname == 'WX4AKQ_NCO_Report_Form' && $xml->variables->relayedvia == '6') { $rejected_due_to_hold = true; } $success = true; if (!$rejected_due_to_acl && !$rejected_due_to_hold) { $ch = curl_init(); if (class_exists('CurlFile')) { $uploadFile = new CurlFile($filename, mime_content_type($filename), $filename); $uploadFile->setPostFilename(basename($filename)); } else { if (!function_exists('curl_file_create')) { function curl_file_create($filename, $mimetype = '', $postname = '') { return "@{$filename};filename=" . ($postname ?: basename($filename)) . ($mimetype ? ";type={$mimetype}" : ''); } } $uploadFile = curl_file_create($filename, mime_content_type($filename), $filename); } $data = array('attachment[]' => $uploadFile, 'output' => 'xml'); $opt_array = array(CURLOPT_URL => $Config['upload_url'], CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $data); curl_setopt_array($ch, $opt_array); $result = curl_exec($ch); curl_close($ch);
protected static function upload($path, $file, $body, $options, $method = 'POST') { $client = new CurlClient(); $c_file = new \CurlFile($file, null, $method == 'POST' ? 'source_video' : 'custom_poster_frame'); $c_file->setPostFilename(basename($file)); if (is_null($body)) { $body = array(); } array_push($body, $c_file); $response = $client->upload($path, $body, $options, $method); return $response; }
/** * @param string $filePath * @param string $filename * @param null|string $typeId used for internal unistorage statistics * * @return File */ public function uploadFile($filePath, $filename = '', $typeId = null) { if (empty($filename)) { $filename = pathinfo($filePath, PATHINFO_BASENAME); } if (class_exists('\\CurlFile', false)) { // PHP >= 5.5 $file = new \CurlFile($filePath); $file->setPostFilename($filename); } else { // PHP < 5.5 $file = "@{$filePath};filename={$filename}"; } $fields = array('file' => $file); if (!is_null($typeId)) { $fields += array('type_id' => $typeId); } $answer = $this->sendRequest('/', $fields, 'post'); return $this->getFile($answer['resource_uri']); }