首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >move_uploaded_file不支持ng-file-upload

move_uploaded_file不支持ng-file-upload
EN

Stack Overflow用户
提问于 2016-06-10 17:11:48
回答 1查看 261关注 0票数 0

我正在尝试上传图片到服务器,也插入到数据库的路径。对数据库的插入工作正常,在客户端(内置angular)上传后,文件似乎可以在$_FILES中找到。但是move_uploaded_file函数返回false,并且文件不会移动到任何地方。可能的问题是什么?

VIEW.html

代码语言:javascript
复制
<div class="insert col-lg-3 col-sm-12">
 <input type="file" name="file" ngf-select="uploadFiles($file)" ngf-pattern="'image/*'"  />
</div>

CONTROLLER.js

代码语言:javascript
复制
 $scope.uploadFiles = function(file) {
        console.log(file);
        Upload.upload({
          url: '../backend/index.php/user/uploadfile?id=' + 1,
          method: 'POST',
          file: file,
          sendFieldsAs: 'form'
        }).then(function successCallback (response)  {
              console.log(response.data);
        });
      };

USER.php

代码语言:javascript
复制
 /**
 * @param $id
 * @url uploadfile
 * @return bool
 */

public function postUploadfile($id){

    $mysqli = $this->db-> getConnection();  

    if(isset($_FILES)) {
      $this->pic = new Pictures($mysqli);
      $picture = $this->pic->upload($_FILES['file'], "", "book", $id);
    }    
}

PICTURES.CLASS.php

代码语言:javascript
复制
namespace BC; 

class pictures {

  private $img_path = 'test/';
  private $m_conn;

  function __construct(&$mysqli_conn) {
    $this->m_conn = $mysqli_conn;
  }

  /*
   * Finishing the upload of an image and creates the nessecary rows in the
   * database.
   *
   * @param array $FILE Contains the element image_file which is an uploaded file
   * @param string $description Description of the image
   * @param string $type Which type should this belong to? Eg. periodical
   * @param int $foreign_key The index of the row this image belongs to
   *
   * @return boolean True if everything went fine, otherwise false.
   */

  public function upload($FILE, $description, $type, $foreign_key) {
    // Insert into database
    $SQL = 'INSERT INTO pictures (description) VALUE ("' . $description . '")';


    if(!$this->m_conn->query($SQL)) {
      return false;
    }

    // Get the id
    $id = $this->m_conn->insert_id;
    move_uploaded_file($_FILES['file']['tmp_name'], $this->img_path . $id . '.jpg');
    return $this->img_path . $id . '.jpg';


    // Create entry for it
    $SQL = 'INSERT INTO picture_connections (picture_id, type, foreign_key) VALUES (' . $id . ', "' . $type . '", ' . $foreign_key . ')';
    if(!$this->m_conn->query($SQL)) {
      return false;
    }
    return true;
  }

}

文件夹测试放置在与pictures.class.php相同的级别中,并且具有正确的权限。似乎想不出这件事。

EN

回答 1

Stack Overflow用户

发布于 2016-06-10 18:57:02

这是一个路径问题!我通过更改private $img_path = 'test/';解决了这个问题

到私有$img_path = '/Applications/MAMP/htdocs/project/test/';

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37744329

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档