我有麻煩讓用戶上傳文件到我的php程序在谷歌應用程序引擎上運行。我正在嘗試關注this google manual。如何讓用戶從谷歌應用引擎直接上傳到谷歌數據存儲?
我用CodeIgniter 3個工作,我設置了以下控制器:
Projecteditor.php:
public function index($cluster_id)
{
if($this->require_min_level(1))
{
$project_access_lvl = $this->check_access_lvl($cluster_id);
if($project_access_lvl >= 0)
{
// Upload files to Google Cloud Storage
$my_bucket = 'THE_ID.appspot.com';
$options = ['gs_bucket_name' => $my_bucket]; //todo app id
$upload_url = CloudStorageTools::createUploadUrl('/main.php/upload/handler', $options);
$view_data['upload_url'] = $upload_url;
// Display webpage
$cluster = $this->cluster_model->get_cluster_by_id($cluster_id)[0];
$project = $this->project_model->get_projects($cluster['projecten_project_id'])[0];
$view_data['fase_details'] = $this->get_fase_details($cluster['fase']);
$view_data['project_name'] = $project['naam'];
echo $this->load->view('templates/header', '', TRUE);
echo $this->load->view('projecteditor/index', (isset($view_data)) ? $view_data : '', TRUE);
echo $this->load->view('templates/footer', '', TRUE);
}
else
{
// TODO syslog
}
}
}
upload.php的:
public function handler()
{
$my_bucket = 'THE_ID.appspot.com';
# [START move_uploaded_file]
$file_name = $_FILES['uploaded_files']['name'];
$temp_name = $_FILES['uploaded_files']['tmp_name'];
move_uploaded_file($temp_name, "gs://${my_bucket}/${file_name}.txt");
# [END move_uploaded_file]
return sprintf('Your file "%s" has been uploaded.', $file_name);
}
當然我取代THE_ID與正確的桶ID。
,與Projecteditor控制器所對應的視圖內的形式:
<?php
echo form_open($upload_url, array('enctype' => 'multipart/form-data'));
?>
<div class="col-lg-12">
<div id="my-dropzone" class="dropzone" action="#">
<div class="dropzone-previews"></div>
<button type="submit" class="btn btn-success pull-right"><i class="fa fa-upload"></i> <span class="bold">Upload</span></button>
</div>
</div></div>
<?php echo form_close(); ?>
這些文件通過使用jQuery保管箱插件上載。 我懷疑我在CloudStorageTools :: createUploadUrl中輸入了錯誤的相對URL,但我無法真正發現我應該輸入的相對URL。
兩個控制器的絕對網址是:
Projecteditor.php: https://example.com/projecteditor/index/SOME_VARIABLE
upload.php的: https://example.com/main.php/upload/handler
當我的代碼執行,我收到了郵寄到Projecteditor.php但而不是Upload.php,數據存儲區保持空白。
我也使用this source關於谷歌存儲桶。
請讓我知道如果我做錯了什麼或有其他方式(更簡單的方法)來存儲我的數據。
在此先感謝