{"id":4565,"date":"2023-11-07T15:50:34","date_gmt":"2023-11-07T15:50:34","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=4565"},"modified":"2025-12-04T19:40:14","modified_gmt":"2025-12-04T19:40:14","slug":"remote-files","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/php\/files\/remote-files","title":{"rendered":"Remote files"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Copy a remote file to local server<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  $FileUrl = \"http:\/\/mydomain.com\/myimage.jpg\";\n  $ch = curl_init($FileUrl);\n  $FileName = basename($FileUrl);    \/\/ Get the file name and extension using basename()\n  $SavePath = $_SERVER&#91;'DOCUMENT_ROOT'] . '\/myfolder\/mysavedfilename.jpeg';\n  $fp = fopen($SavePath, 'wb');\n  \n  curl_setopt($ch, CURLOPT_FILE, $fp);    \/\/ Set the file transfer option and header to CURL\n  curl_setopt($ch, CURLOPT_HEADER, 0);\n\n  $CurlResult = curl_exec($ch);     \/\/ Execute the CURL session\n  fclose($fp); \n\n  \/\/Check for curl errors\n  if ($CurlResult === False)\n  {\n    fclose($fp);\n    return(False);\n  }\n\n  \/\/Check HTTP response code\n  $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);\n  fclose($fp);\n\n  if ($http_code !== 200)\n  {\n    unlink($SavePath);        \/\/Delete possibly incomplete file\n    return(False);\n  }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Copy a remote file to local server<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[157,58],"tags":[],"class_list":["post-4565","post","type-post","status-publish","format-standard","hentry","category-curl","category-files"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/4565","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=4565"}],"version-history":[{"count":6,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/4565\/revisions"}],"predecessor-version":[{"id":5248,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/4565\/revisions\/5248"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=4565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=4565"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=4565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}