{"id":305,"date":"2012-04-27T15:11:38","date_gmt":"2012-04-27T15:11:38","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=305"},"modified":"2022-02-17T07:14:04","modified_gmt":"2022-02-17T07:14:04","slug":"upload-a-server-file","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/platforms\/aws\/s3\/upload-a-server-file","title":{"rendered":"Upload A Server File"},"content":{"rendered":"<p>\n<em><span style=\"color:#FF0000;\">This uses an old aws method<\/span><\/em>\n<\/p>\n<h4>\nUpload A Saved File<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\t$upload_file = \r\n\tif (file_exists($upload_file))\r\n\t{\r\n\t\ttry\r\n\t\t{\r\n\t\t\t$options = array(&#39;key&#39; =&gt; $s3_accesskey, &#39;secret&#39; =&gt; $s3_secretkey);\r\n\t\t\t$s3 = new AmazonS3($options);\r\n\t\r\n\t\t\t\/\/Upload file\r\n\t\t\t$response = $s3-&gt;create_object($s3_thumbnails_bucket, basename($upload_file), array(\r\n\t\t\t\t\t&#39;fileUpload&#39; =&gt; $upload_file,\r\n\t\t\t\t\t\/\/&#39;storage&#39; =&gt; AmazonS3::STORAGE_REDUCED,\r\n\t\t\t\t\t&#39;acl&#39; =&gt; AmazonS3::ACL_PUBLIC\r\n\t\t\t\t\t));\r\n\t\t\r\n\t\t\tif ($response-&gt;isOK())\r\n\t\t\t\t\techo &quot;Upload  success&quot;;\r\n\t\t\telse\r\n\t\t\t\t\techo &quot;Upload failed&quot;;\r\n\t\t}\r\n\t\tcatch (Exception $e)\r\n\t\t{\r\n\t\t\techo &#39;Upload exception: &#39;,  $e-&gt;getMessage(), &quot;&lt;br \/&gt;&quot;;\r\n\t\t}\r\n\t}\r\n<\/code><\/pre>\n<h4>\nUpload An Open File<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\ttry\r\n\t{\r\n\t\t$options = array(&#39;key&#39; =&gt; $s3_accesskey, &#39;secret&#39; =&gt; $s3_secretkey);\r\n\t\t$s3 = new AmazonS3($options);\r\n\t\t\r\n\t\t\/\/Open the file\r\n\t\t$fileResource = fopen($output_file, &#39;r&#39;);\r\n\t\r\n\t\t\/\/Upload file\r\n\t\t$response = $s3-&gt;create_object($s3_thumbnails_bucket, basename($output_file), array(\r\n\t\t\t\t&#39;fileUpload&#39; =&gt; $fileResource,\r\n\t\t\t\t\/\/&#39;storage&#39; =&gt; AmazonS3::STORAGE_REDUCED,\r\n\t\t\t\t&#39;acl&#39; =&gt; AmazonS3::ACL_PUBLIC\r\n\t\t\t\t));\r\n\t\r\n\t\tif ($response-&gt;isOK())\r\n\t\t\t\techo &quot;Upload  success&quot;;\r\n\t\telse\r\n\t\t\t\techo &quot;Upload failed&quot;;\r\n\t}\r\n\tcatch (Exception $e)\r\n\t{\r\n\t\techo &#39;Upload exception: &#39;,  $e-&gt;getMessage(), &quot;&lt;br \/&gt;&quot;;\r\n\t}\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This uses an old aws method Upload A Saved File $upload_file = if (file_exists($upload_file)) { try { $options = array(&#39;key&#39; =&gt; $s3_accesskey, &#39;secret&#39; =&gt; $s3_secretkey); $s3 = new AmazonS3($options); \/\/Upload file $response = $s3-&gt;create_object($s3_thumbnails_bucket, basename($upload_file), array( &#39;fileUpload&#39; =&gt; $upload_file, \/\/&#39;storage&#39; =&gt; AmazonS3::STORAGE_REDUCED, &#39;acl&#39; =&gt; AmazonS3::ACL_PUBLIC )); if ($response-&gt;isOK()) echo &quot;Upload success&quot;; else echo &quot;Upload failed&quot;; [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[40],"tags":[],"class_list":["post-305","post","type-post","status-publish","format-standard","hentry","category-s3"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/305","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=305"}],"version-history":[{"count":8,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/305\/revisions"}],"predecessor-version":[{"id":1864,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/305\/revisions\/1864"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=305"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}