dongpan1416
2015-05-23 04:50
浏览 121
已采纳

为什么在这个函数之后没有执行file_put_contents()代码行?

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>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doukekui0914 2015-05-23 08:04
    已采纳

    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..

    点赞 打赏 评论
  • douduan6731 2015-05-23 04:55

    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:

    点赞 打赏 评论

相关推荐 更多相似问题