Skip to content

Instantly share code, notes, and snippets.

@bcls
Last active May 28, 2023 20:10
Show Gist options
  • Save bcls/2c9bc400278f3cbdfe1420bac1f23fe1 to your computer and use it in GitHub Desktop.
Save bcls/2c9bc400278f3cbdfe1420bac1f23fe1 to your computer and use it in GitHub Desktop.
PHP PUT file #php
$file = fopen($file_on_dir_not_url, "rb");
$curl = curl_init();
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_BINARYTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_PUT, true);
curl_setopt($curl, CURLOPT_INFILE, $file);
curl_setopt($curl, CURLOPT_INFILESIZE, filesize($file_on_dir_not_url));
$result = curl_exec($curl);
curl_close($curl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment