move_uploaded_file在GCS中返回TRUE但没有文件

时间:2014-07-18 17:07:43

标签: php google-app-engine google-cloud-storage

对此非常陌生,一直试图让它发挥作用。 我有一个名为app的桶。我按照说明将我的应用权限授予GCS(https://developers.google.com/appengine/docs/python/googlestorage/index#Prerequisites)。它似乎设置正确。

我跟着How do I upload images to the Google Cloud Storage from PHP form?跟随其他人工作过。我并没有真正转移它。

我的move_uploaded_file返回TRUE,但GCS中没有文件。

输出是“MoveResult确实成功”。 任何人都看到我做错了什么。我错过了一些设置代码吗?

以下是代码:

if(!is_uploaded_file($_FILES['file']['tmp_name'])) { 
     $profile_pic_path='default';
}
else { //file exists
    $gs_name = $_FILES["file"]["tmp_name"]; 

    $fileType = $_FILES["file"]["type"]; 
    $fileSize = $_FILES["file"]["size"]; 
    $fileErrorMsg = $_FILES["file"]["error"]; 
    $fileExt = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);

    // change name if you want
    $fileName = 'profile_pic.jpg';

    // put to cloud storage
    $image = file_get_contents($gs_name);
    $options = [ "gs" => [ "Content-Type" => "image/jpeg"]];
    $ctx = stream_context_create($options);
    //file_put_contents("gs://app/".$fileName, $gs_name, 0, $ctx);
    if(!move_uploaded_file($gs_name, 'gs://app/'.$fileName)){
        echo json_encode(array('success' => 0,'error_message' => "MoveResult did not succeed"));
        exit;
    }
    else{
        //Get image key in or path or what not. THIS IS THE NEXT STEP
        //$profile_pic_path=<something>;
        echo json_encode(array('success' => 1,'info_message' => "MoveResult did succeed"));
        exit;
    }

}

0 个答案:

没有答案
相关问题