$ch = curl_init();
$file = fopen($media, 'r');
$chunk_id = 0;
while (!feof($file)) {
$append_headers = array();
$chunk = fread($file, 1048576);
$boundary = $chunk_id.time();
$params = "--" . $boundary . "\r\n"
. "Content-Type: video/mp4\r\n"
. "Content-Disposition: form-data; name=\"media\"; filename=\"blob\"\r\n"
. "\r\n"
. $chunk . "\r\n"
. "--" . $boundary . "--";
$append_headers[] = 'Content-Length: ' . strlen($params);
$append_headers[] = 'Content-Type: multipart/form-data; boundary=' . $boundary;
curl_setopt($ch, CURLOPT_HTTPHEADER, $append_headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_USERAGENT, $this->curl_config['useragent']);
curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookie_dir . md5($this->UserName . $this->Password));
curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie_dir . md5($this->UserName . $this->Password));
curl_setopt($ch, CURLOPT_URL, 'https://upload.twitter.com/i/media/upload.json?command=APPEND&media_id=' . $init->media_id . '&segment_index=' . $chunk_id);
$response = curl_exec($ch);
$chunk_id++;
}
This is my solution for placing pieces. It works great.
source
share