upload and retrieve image from angular to php server
<p>I created the application using ionic and angular with php back end.</p>

<p>I can able to upload the image from angular to php server as per below workouts.</p>

<blockquote>
  <p>Upload.js</p>
</blockquote>

<pre><code>$scope.onProfileFileSelect = function($files) {
//$files: an array of files selected, each file has name, size, and type.
for (var i = 0; i &lt; $files.length; i++) {
var $file = $files[i];
console.log($file.name);
$upload.upload({
url: 'http://www.testphp.com/upload.php',
file: $file,
progress: function(e){}
}).then(function(response) {
// file is uploaded successfully
$timeout(function() {
console.log(response.data);
});
}); 
}
}
</code></pre>

<blockquote>
  <p>Upload.html </p>
</blockquote>

<pre><code>&lt;div class="item item-input item-icon-right"&gt;
&lt;span class="input-label"&gt;Capture your profile picture: &lt;/span&gt;                
&lt;input type="file" name="ProfilePath" ng-model="inmateData.IMProfilePhotoPath" ng-file-select="onProfileFileSelect($files)" multiple /&gt;
&lt;/div&gt;
</code></pre>

<blockquote>
  <p>Upload.php</p>
</blockquote>

<pre><code>&lt;?php

if (isset($_SERVER['HTTP_ORIGIN'])) 
{
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400');    // cache for 1 day
}

// Access-Control headers are received during OPTIONS requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {

if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");         

if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
header("Access-Control-Allow-Headers:        {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");

exit(0);
}

$target_dir = "Inmate_Images/";
$target_file = $target_dir . basename($_FILES["file"]["name"]);
$result = move_uploaded_file($_FILES["file"]["tmp_name"], $target_file);
echo json_encode($_FILES["file"]);
echo($result);
?&gt;
</code></pre>

<p>As of now I can able to upload the selected image and stored in my PHP server "Inmate_Images" folder. </p>

<blockquote>
  <p>My requirement is :</p>
</blockquote>

<ol>
<li><p>I need to change the image file name and then upload it in server.</p></li>
<li><p>And how to get the image using get request and the name which I have given while upload. ??</p></li>
</ol>

<p>How to handle this activity any idea ?</p>