我想將圖像上傳到S3,但圖像正在上傳,但大小爲0字節,與源文件不同。不知道我做錯了什麼,任何人都可以指導我正確的方向請。使用AWS PHP SDK將圖像保存到S3
upload.php的低於
<!DOCTYPE html>
<html>
<body>
<form action="save.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>
save.php
<?php
include 'connecttoaws.php'
$bucket = 'xyxdskjflsdafjsakf';
$file = $FILES["img"]["name"];
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["img"]["tmp_name"]);
if($check !== false) {
$uploadOK = 1;
$result = $client->putObject(array(
'Bucket' => $bucket,
'ContentType' => 'image/png',
'Key' => $file
));
echo 'Image Uploaded';
}
else{
echo "File not uploaded";
$uploadOK = 0;
}
輸出:
圖片上傳
的文件是可在S3上,但大小爲0。我究竟做錯了什麼?