i have created one function to upload image using web services.
$image_url=time().$img_name;
$path=$_SERVER['DOCUMENT_ROOT'].'/img';
$image_url_src=$path."/".$image_url;
$current = file_get_contents($image_url_src);
$current = base64_decode($img_url);
$res=file_put_contents($image_url_src,$current);
chmod($image_url_src, 0777);
if($res===true)
{
$folder_img_url1="http://www.example.com/img/".$image_url;
$auth_error=array("img_url" => $folder_img_url1);
return json_encode($auth_error);
}
Everything is working properly.. only problem is why not returning value after this line of code file_put_contents($image_url_src,$current);
if i return any value before file_put_contents function than it works but after calling file_put_contents()
after that not return works so why?
ANY HELP WOULD BE APPRECIATED
</div>
This Code is works for me...
$image_url=time().$img_name;
$path=$_SERVER['DOCUMENT_ROOT'].'/img';
$image_url_src=$path."/".$image_url;
//$current = file_get_contents($image_url_src); //this line of code is no need because of this not returning value..because it gives me an error.
$current = base64_decode($img_url);
$res=file_put_contents($image_url_src,$current);
//chmod($image_url_src, 0777); if will remove than also its works
if($res===true)
{
$folder_img_url1="http://www.example.com/img/".$image_url;
$auth_error=array("img_url" => $folder_img_url1);
return json_encode($auth_error);
}
Thank you for your time..
There is problem with permission of folder
First give permission
<?php
chmod($image_url_src, 0777);
if (file_put_contents($image_url_src,$current)!== false) {
{
$folder_img_url1="http://www.example.com/img/".$image_url;
$auth_error=array("img_url" => $folder_img_url1);
return json_encode($auth_error);
}
This function returns the number of bytes that were written to the file, or FALSE on failure. Meaning: file_put_contents will never return TRUE. It will return false however, so if you were insistent on using a boolean value then you would need to use: