1
我對這一切都很新穎。我正嘗試從iPhone應用中上傳圖片,並使用PHP將其存儲到我的Google Cloud Storage存儲桶(gs:// app/users/profile_pics /)中。我可以使用本地文件系統執行此操作,但它不適用於Google雲端存儲。以PHP格式從Google雲端存儲中上載和檢索圖片
**iOS Code (this works)**
...
[body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:profile_pic_data]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
...
**PHP Code to local file system (works using local file system)**
if($_POST) {
...
//Make user directory to house files
$upload_dir = 'user_data/' . $user_id . '/';
$path = mkdir("$upload_dir", 0777);
//Save file to newly created folder
$file = 'profile_pic.jpg';
$profile_pic_path = $upload_dir . $file;
if (move_uploaded_file($_FILES['file']['tmp_name'], $profile_pic_path)) {
//Profile pic uploaded, Update profile pic field in database
$query = "UPDATE users SET profile_image_path='$upload_path' WHERE email='$user_email'";
if(mysql_query($query)){
echo json_encode(array('success' => 1,'info_message' => "")); // Account fully created!
}
...
**PHP using Google Cloud Storage (not working, trying the most simple version first)**
...
if($_POST) {
...
$gs_name = $_FILES['file']['tmp_name'];
move_uploaded_file($gs_name, 'gs://socalityapp/users/profile_pics/profile_pic.jpg');
...
我似乎無法得到它存儲。我知道我的其他PHP正在工作,因爲我正在將配置文件保存到我的Google Cloud SQL數據庫中。
幫助或批評(iOS,PHP等)將非常感激!
誰能幫助? – lr100
您是否在日誌中看到任何錯誤/警告消息? – Mars