帮助将图像上传到 EC2 实例(Flash -> PHP)
我开发了一个图像上传应用程序,它使用 Flash 加载图像、调整图像大小并将图像数据的字节数组发送到 PHP 文件,该文件使用以下代码输出调整大小的文件 -
$default_path = '/uploads/temp/';
$filename = $_GET["filename"];
$destination = $default_path . $filename;
if(file_put_contents($destination, $GLOBALS["HTTP_RAW_POST_DATA"])) {
echo "The file " . basename( $_FILES[ 'Filedata' ][ 'name' ] ) . " has been uploaded;";
} else {
echo "FILE UPLOAD FAILED";
}
当我从专用的 Windows 2003 Web 服务器,但现在我尝试在 EC2 实例上运行它,它已停止工作,我只收到“文件上传失败”消息。我可以从 Firefox 的 Firebug 附加组件看出,字节数组数据已正常发布到 EC2 实例,但无法看出还有什么原因会导致问题。
在 EC2 上,我正在运行安装了 PHP 和 Apache 的 CentOS 映像,我不知道从哪里开始解决这个问题!请告诉我我需要在这里寻找什么问题,有什么想法吗?
我检查了错误日志并收到以下错误消息 -
file_put_contents(/uploads/temp/abcdefg.JPG) [<a href='function.file-put-contents'>function.file-put-contents</a>]: failed to open stream: No such file or directory
这是否与指向错误目录有关?或像下面有人所说的权限?如何授予 PHP 写入此目录的权限?我应该使用绝对路径来引用我想要写入图像的目录吗?
干杯
I have developed an image uploading application that uses Flash to load an image, resize the image and send the bytearray of the image data to a PHP file that outputs the resized file using the following code -
$default_path = '/uploads/temp/';
$filename = $_GET["filename"];
$destination = $default_path . $filename;
if(file_put_contents($destination, $GLOBALS["HTTP_RAW_POST_DATA"])) {
echo "The file " . basename( $_FILES[ 'Filedata' ][ 'name' ] ) . " has been uploaded;";
} else {
echo "FILE UPLOAD FAILED";
}
This worked great when I was running it from a dedicated windows 2003 web server but now that I am trying to run this on an EC2 instance it has stopped working and I only get the "File Upload Failed" message. I can tell from Firefox's Firebug add-on that the bytearray data is being posted to the EC2 instance ok but cannot see what else would be causing the problem.
on EC2 I am running a CentOS image with PHP and Apache installed, I dont event know where to start troubleshooting this one! Please tell me what issues i need to be looking for here, any ideas?
I checked the error logs and get the following error message -
file_put_contents(/uploads/temp/abcdefg.JPG) [<a href='function.file-put-contents'>function.file-put-contents</a>]: failed to open stream: No such file or directory
Is this to do with pointint to the wrong directory? or permissions as someone has stated below? How do I give PHP permission to write to this directory and should I use absolute path to reference the directory I want to write the image to?
cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能是权限问题,可能是php用户没有写入指定目录的权限。
apache 错误日志中是否有任何消息?
Could be a permission problem, maybe the php user does not have permission to write to the specified directory.
Do you have any messages in the apache error log?
我不知道您是否愿意与其他课程一起工作,但是有一些 PHP EC2 课程可能会有所帮助 - http://sourceforge.net/projects/php-ec2/
I don't know if your willing to work with other's classes, but there are a few PHP EC2 classes around which may help - http://sourceforge.net/projects/php-ec2/