doumengwei0138 2011-12-14 03:36
浏览 32
已采纳

iOS应用程序的PHP is_uploaded_file失败

I'm writing the PHP/webserver side of an image upload for an iOS app. Using an html file I can upload an image to my script just fine. I've even written a Perl LWP script to post an image with no problems.

When the iOS app uploads an image it fails when I call is_uploaded_file. Sending back the $_FILES var in the json response show us what we expect for a file upload. Also I do a file_exists on the tmp_name and that fails as well.

Is there anything else I can look at in the request to determine what is going wrong? I'd like to be able to indicate what's wrong with the post request.

Here's the block of code where it stop processing the image upload:

    //Check for valid upload
    if(!is_uploaded_file($_FILES['photo']['tmp_name'])) {
        $this->errors['upload_2'] = $photoErrorString;
        $this->errors['files'] = $_FILES;
        $this->errors['image_uploaded'] = file_exists($_FILES['photo']['tmp_name']);
        error_log("uploadPhoto: upload_2");
        return false;
    }
  • 写回答

2条回答 默认 最新

  • drmcm84800 2011-12-14 04:47
    关注

    As far as i know you cannot upload a image or photo from iOS app directly using PHP scripts.

    You have to send 64 bit encode from the iOS app to the script responsible for the file upload as a simple POST. Then that script will firstly decode your photo's string and then PHP script will create the image from the string only to upload.

    Code will be something like:

    $filedb = $path_to_dir.$file_name_of_the_photo;
    $profile_pic = $_POST['profile_pic'];
    $profile_pic= base64_decode($profile_pic);
    if(($img = @imagecreatefromstring($profile_pic)) != FALSE) 
    {
      if(imagepng($img,$filedb))//will create image and save it to the path from the filedb with the name in variable file_name_of_the_photo
      {
    imagedestroy($img);// distroy the string of the image after successful upload
    // do other updates to database if required
      }
      else //cannot create imagepng Error
      { 
    //do what required
      }
    }
    

    Hope this will work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?