Skip to content

Instantly share code, notes, and snippets.

@msg7086
Created October 1, 2013 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msg7086/6784049 to your computer and use it in GitHub Desktop.
Save msg7086/6784049 to your computer and use it in GitHub Desktop.
<?php
require_once dirname ( __FILE__ ) . '/' . 'RequestCore.class.php';
class BaiduPCS {
public function uploadFile($fullFilename, $remoteFilename, $isTemp = FALSE)
{
$url = 'file?method=upload&access_token=' . $this->_accessToken . '&path=' . urlencode($remoteFilename) . ($isTemp?'&type=tmpfile':'');
if(PHP_VERSION_ID >= 50500 && class_exists('CURLFile'))
$post = ['file_contents' => new CURLFile($fullFilename)];
else
$post = ['file_contents' => '@'.$fullFilename];
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $this->_pcs_uri_prefixs['https'] . $url);
curl_setopt($curl_handle, CURLOPT_POST, TRUE);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $post);
curl_setopt($curl_handle, CURLOPT_FILETIME, true);
curl_setopt($curl_handle, CURLOPT_FRESH_CONNECT, false);
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl_handle, CURLOPT_CLOSEPOLICY, CURLCLOSEPOLICY_LEAST_RECENTLY_USED);
curl_setopt($curl_handle, CURLOPT_MAXREDIRS, 5);
curl_setopt($curl_handle, CURLOPT_HEADER, false);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle, CURLOPT_TIMEOUT, 5184000);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($curl_handle, CURLOPT_NOSIGNAL, true);
$result = curl_exec($curl_handle);
return $result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment