我在上传图片到S3时遇到了问题。我使用S3类和jqueryimageuploader插件来完成此操作。
我已经建立了基本应用程序,并且在我的本地机器上运行良好。但是,当我部署它到beanstalk时,它就开始抛出错误。我已经附上了控制台快照。
下面是我的代码参考:
这是启动文件index.html-
我的 index.php 文件 --> 当文件上传按钮被点击时会调用此文件。
![enter image description here](https://istack.dev59.com/KClrK.webp)
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>jQuery File Upload Example</title>
</head>
<body>
<input id="fileupload" type="file" name="files[]" data-url="http://mydomain.elasticbeanstalk.com/server/php/index.php" multiple>
<script src="js/jquery.min.js"></script>
<script src="js/vendor/jquery.ui.widget.js"></script>
<script src="js/jquery.iframe-transport.js"></script>
<script src="js/jquery.fileupload.js"></script>
<script>
$(function () {
$('#fileupload').fileupload({
dataType: 'json',
done: function (e, data) {
$.each(data.result.files, function (index, file) {
$('<p/>').text(file.name).appendTo(document.body);
});
}
});
$('#fileupload').fileupload({
/* ... */
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#progress .bar').css(
'width',
progress + '%'
);
}
});
});
</script>
<style>
.bar {
height: 18px;
background: green;
}
我的 index.php 文件 --> 当文件上传按钮被点击时会调用此文件。
<?php
error_reporting(E_ALL | E_STRICT);
require('UploadHandler.php');
$upload_handler = new UploadHandler();
?>
uploadHandler.php 文件可以在这里找到。
我将添加由我修改的部分来上传至S3。
$bucket = "my bucket nmae";
$s3 = new S3(awsAccessKey, awsSecretKey);
$response = $s3->putObjectFile($file_path,$bucket,$file->name,S3::ACL_PUBLIC_READ);
$thumbResponse = $s3->putObjectFile('files/thumbnail/'.$file->name,$bucket,'images /'.$file->name,S3::ACL_PUBLIC_READ);
echo $response;
echo $thumbResponse;
if ($response==1) {
echo 'HERER enter!!';
} else {
$file->error = "<strong>Something went wrong while uploading your file... sorry.</strong>";
}
我并没有上传太 大 的文件,在本地机器上运行得很好,但在 beanstalk 上却失败了。任何帮助都将不胜感激。谢谢关注。