Php 在引用图像时,$\u FILES中的文件是否与file\u get\u内容相同?
这就是说,$uploaded\u image是否使用以下“相同”变量:Php 在引用图像时,$\u FILES中的文件是否与file\u get\u内容相同?,php,amazon-s3,Php,Amazon S3,这就是说,$uploaded\u image是否使用以下“相同”变量: $uploaded_image = $_FILES['picture']['tmp_name']; 还是这个 $uploaded_image = file_get_contents($some_image_url); 这样我就可以以同样的方式将图像上传到第三方服务器,而不依赖于上面的哪个代码uploadToOtherServer($uploaded_image)(我确信此功能在第一种情况下有效,第二种情况如何?)感谢您的
$uploaded_image = $_FILES['picture']['tmp_name'];
还是这个
$uploaded_image = file_get_contents($some_image_url);
这样我就可以以同样的方式将图像上传到第三方服务器,而不依赖于上面的哪个代码uploadToOtherServer($uploaded_image)
(我确信此功能在第一种情况下有效,第二种情况如何?)感谢您的帮助
PS:考虑到两幅图像完全相同
编辑:更进一步,我将上传到S3。这项工作:
$result = $s3->putObject(array(
'Bucket' => $bucket,
'Key' => $file_path,
'ACL' => 'public-read',
'ContentType' => $content_type,
'SourceFile' => $_FILES['profile_picture']['tmp_name']
));
这也行吗
$result = $s3->putObject(array(
'Bucket' => $bucket,
'Key' => $file_path,
'ACL' => 'public-read',
'ContentType' => $content_type,
'SourceFile' => file_get_contents($image_url)
));
只需传递绝对文件url e、 因此,它读作
$result = $s3->putObject(array(
'Bucket' => $bucket,
'Key' => $file_path,
'ACL' => 'public-read',
'ContentType' => $content_type,
'SourceFile' => 'http://www.example.com/image.jpg',
));
下面的表单登录应该可以让您继续
参考:
下面表格中的概念应该会让你开始学习
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<form action="http://examplebucket.s3.amazonaws.com/" method="post" enctype="multipart/form-data">
Key to upload:
<input type="input" name="key" value="user/user1/${filename}" /><br />
<input type="hidden" name="acl" value="public-read" />
<input type="hidden" name="success_action_redirect" value="http://examplebucket.s3.amazonaws.com/successful_upload.html" />
Content-Type:
<input type="input" name="Content-Type" value="image/jpeg" /><br />
<input type="hidden" name="x-amz-meta-uuid" value="14365123651274" />
<input type="text" name="X-Amz-Credential" value="AKIAIOSFODNN7EXAMPLE/20130806/us-east-1/s3/aws4_request" />
<input type="text" name="X-Amz-Algorithm" value="AWS4-HMAC-SHA256" />
<input type="text" name="X-Amz-Date" value="20130806T000000Z" />
Tags for File:
<input type="input" name="x-amz-meta-tag" value="" /><br />
<input type="hidden" name="Policy" value='<Base64-encoded policy string>' />
<input type="hidden" name="X-Amz-Signature" value="<signature-value>" />
File:
<input type="file" name="file" /> <br />
<!-- The elements after this will be ignored -->
<input type="submit" name="submit" value="Upload to Amazon S3" />
</form>
</html>
要上载的密钥:
内容类型:
文件的标记:
文件:
$\u文件['picture']['tmp\u name']
和$some\u image\u url
都是指向文件的路径。它们不是原始文件数据
但是如果你有
$uploaded_image = file_get_contents($_FILES['picture']['tmp_name']);
然后两者都是等价的-变量中有表示文件的二进制数据。n不,一个是文件名,另一个是文件内容。@Musa我已经更新了我的问题,您想看一下吗?:)这取决于具体的API,也就是说,我认为它不会工作。参数名为
SourceFile
,因此看起来它需要一个可自行读取的文件名,而不是实际的文件数据。您的回答是否说明将URL传递到SourceFile
足以满足S3 API的要求?请回答@Mjh alpesh这不起作用stackoverflow.com/questions/34251296/cant-upload-image-to-s3-bucket-using-direct-url-of-image/34253844Pretty类似问题,如果您有空闲时间,请查看