也就是说,$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)
));
$_FILES['picture']['tmp_name']
和$some_image_url
都只是指向文件的路径。它们不是原始文件数据。
但如果你有
$uploaded_image = file_get_contents($_FILES['picture']['tmp_name']);
那么两者都是等价的——在变量中有表示文件的二进制数据。
只需传递绝对文件url。。
例如。http://www.example.com/image.jpg所以它读起来像
$result = $s3->putObject(array(
'Bucket' => $bucket,
'Key' => $file_path,
'ACL' => 'public-read',
'ContentType' => $content_type,
'SourceFile' => 'http://www.example.com/image.jpg',
));
按照表格登录应该会让你开始。。。
参考:http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-post-example.html
以下表格中的概念应该会让你开始。
<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>