3 回答

TA貢獻1806條經(jīng)驗 獲得超8個贊
如果仍未解決,那么...正如您提到的 $_FILES 為空,那么我建議查看項目中的文件位置。假設您index.php
在PROJECT->HOME->index.php
目錄中,那么您Next.php
應該在PROJECT->Next.php
目錄中。
你也必須給提交一個name=submit
。
在Next.php
測試中是否設置了任何一種形式
if(isset($_POST['submit'])){
print_r($_FILES['myfile']);
}
如果沒有上傳文件,請告訴我問題所在。

TA貢獻1906條經(jīng)驗 獲得超3個贊
初始設置
由于您的 HTML 文件規(guī)范,我假設您的項目結構如下:
project/
├── templates/
│ └── index.html
└── Next.php
因此,我將使用以下命令在項目文件夾中啟動一個 php 簡單的 http 服務器:php -S localhost:8000
方法
為了讓它工作,你將不得不Next.php稍微調(diào)整你的代碼。我建議使用最新的 Drive APi 版本 (v3)。v3 中沒有方法insert(),但有create().
// Get the API client and construct the service object.
$client = getClient();
$service = new Google_Service_Drive($client);
$myfile=$_FILES['myfile']['tmp_name'];
$fileMetadata = new Google_Service_Drive_DriveFile(array(
'name' => "Test",
));
try{
$newFile = $service->files->create(
$fileMetadata,
array(
'data' => file_get_contents($myfile),
'mimeType' => mime_content_type($myfile),
'uploadType' => 'multipart'
)
);
} catch(Exception $e){
echo 'An error ocurred : ' . $e->getMessage();
}

TA貢獻1850條經(jīng)驗 獲得超11個贊
嘗試添加多部分
$uploadedFile = $service->files->insert($file, array(
'data' => $data,
'mimeType' => $type,
'uploadType' => 'multipart'
));
- 3 回答
- 0 關注
- 147 瀏覽
添加回答
舉報