I am using following code to store images on my webserver:
function SavePic()
{
$allowedExts = array("jpeg", "jpg");
$temp = explode(".", $_FILES["UserPic"]["name"]);
$extension = end($temp);
if ((($_FILES["UserPic"]["type"] == "image/jpeg")
|| ($_FILES["UserPic"]["type"] == "image/jpg"))
//&& ($_FILES["UserPic"]["size"] < 2097152)
&& in_array($extension, $allowedExts))
{
if ($_FILES["UserPic"]["error"] > 0)
{
echo json_encode("Error: ".$_FILES["UserPic"]["error"]);
}
else
{
$folder = "/home5/username/public_html/Project/Users/Images/";
echo move_uploaded_file($_FILES["UserPic"]["tmp_name"],$folder.$_REQUEST["email"].".".$extension);
}
}
else
{
echo json_encode("Invalid file");
}
}
And Following code to retrieve image:
function RetrievePic()
{
$handle = fopen('php://input','r');
$jsonInput = fgets($handle);
// Decoding JSON into an Array
$retrieveParameters = json_decode($jsonInput,true);
$UserPic = array("UserPic" => "http://www.mysite.com/Project/Users/Images/".$retrieveParameters['email']."."."jpg");
echo json_encode($UserPic);
}
For Example if my email is abc@xyz.com then image will be stored as "abc@xyz.com.jpg". The problem is that when I try to overwrite image in order to replace old one with new one, server is returning old one everytime.
Update: When I place url in browser e.g http://www.mysite.com/Project/Users/Images/abc@xyz.com.jpg latest image is shown and after that I start receiving latest image.