2016-06-10 3 views
0

사진을 서버에 업로드하고 데이터베이스 경로를 삽입하려고합니다. db에 대한 삽입이 잘 작동하고 클라이언트 측 (업로드 된 각도)에 업로드 한 후 파일이 $ _FILES에있는 것으로 보입니다. 그러나 move_uploaded_file 함수는 false를 반환하고 파일은 아무데도 움직이지 않습니다. 무엇이 문제 일 수 있습니까?move_uploaded_file이 ng-file-upload와 함께 작동하지 않습니다.

VIEW.html

<div class="insert col-lg-3 col-sm-12"> 
<input type="file" name="file" ngf-select="uploadFiles($file)" ngf-pattern="'image/*'" /> 
</div> 

CONTROLLER.js

$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

/** 
* @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

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와 동일한 레벨에 위치하며 올바른 권한을가집니다. 이 것을 알아낼 수는 없습니다.

+0

private $img_path = 'test/';

을 변경하여이 문제를 해결? 너는 아무 것도 확인하지 않는다. 나는 문제가 있다고 생각한다. 당신이 이미지를 옮긴 직후에 당신이 돌아 오는 것이다. 삽입 된 다음 코드는 절대로 도달하지 않습니다. –

+0

@ RaphaelMüller move_uploaded_file이 false 또는 true를 반환하는 경우 테스트하기 전에 약간 다른 코드를 사용했습니다. 나는 또한 변화를 없애고 복귀를 시도했다. – Nirakander

답변

1

경로 문제였습니다. 나는 인 move_uploaded_file false를 반환 개인 $img_path = '/Applications/MAMP/htdocs/project/test/';