{"id":11231273,"date":"2019-02-21T12:55:58","date_gmt":"2019-02-21T12:55:58","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/cannot-upload-images-49\/"},"modified":"2019-02-21T13:04:31","modified_gmt":"2019-02-21T13:04:31","slug":"cannot-upload-images-49","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/cannot-upload-images-49\/","title":{"rendered":"Cannot upload images"},"content":{"rendered":"<p>I was not able to upload images to a photo gallery. It was giving the error: &#8220;There has been a problem while trying to upload the following images. Please try to upload them again.&#8221;.  I am using the latest version of the Photo Gallery plugin.<\/p>\n<p>I checked using Chrome developers toolbox and it showed 500 internet server error for the ajax call: <strong>bwg_UploadHandler<\/strong>. I checked the code of <strong>filemanager\/UploadHandler.php<\/strong>, which was handling the ajax call. I used Php print and echo commands to locate the error. It turned out the problem was in the function <strong>set_file_info<\/strong>. The function was not handling the case where an image has no credit, aperture, camera, caption, iso, copyright or tags. So if an image has an empty value for one of these properties, then the ajax call fails. I updated the function set_file_info so it checks if the file properties are present. That fixed the error. I was able to upload images. Here is the updated code for set_file_info:<\/p>\n<pre><code>\/**\n   * Set file info.\n   *\n   * @param $info\n   * @return mixed\n   *\/\n  private function set_file_info( $info ) {\n    $data[&#039;is_dir&#039;] = 0;\n    $data[&#039;path&#039;] = $info-&gt;path;\n    $data[&#039;type&#039;] = $info-&gt;type;\n    $data[&#039;name&#039;] = $info-&gt;name;\n    $data[&#039;filename&#039;] = $info-&gt;filename;\n    $data[&#039;alt&#039;] = $info-&gt;alt;\n    $data[&#039;thumb&#039;] = &#039;thumb\/&#039; . $info-&gt;name;\n    $data[&#039;size&#039;] = $info-&gt;size;\n    $data[&#039;resolution&#039;] = $info-&gt;resolution;\n    $data[&#039;credit&#039;] = iconv_mime_decode($info-&gt;credit);\n    $data[&#039;aperture&#039;] = iconv_mime_decode($info-&gt;aperture);\n    $data[&#039;camera&#039;] = iconv_mime_decode($info-&gt;camera);\n    $data[&#039;caption&#039;] = iconv_mime_decode($info-&gt;caption);\n    $data[&#039;iso&#039;] = iconv_mime_decode($info-&gt;iso);\n    $data[&#039;orientation&#039;] = $info-&gt;orientation;\n    $data[&#039;copyright&#039;] = iconv_mime_decode($info-&gt;copyright);\n    $data[&#039;tags&#039;] = iconv_mime_decode($info-&gt;tags);\n    $data[&#039;date_modified&#039;] = date(&#039;Y-m-d H:i:s&#039;);\n    return $data;\n  }\n<\/code><\/pre>\n<p>Please fix this issue and update your plugin. Thanks<\/p>\n","protected":false},"template":"","class_list":["post-11231273","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/11231273","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":1,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/11231273\/revisions"}],"predecessor-version":[{"id":11231287,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/11231273\/revisions\/11231287"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=11231273"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}