问题
I have the following code:
I create the application specific upload URL, using the method CloudStorageTools::createUploadUrl() as follows:
require_once 'google/appengine/api/cloud_storage
/CloudStorageTools.php';
use google\appengine\api\cloud_storage\CloudStorageTools;
$options = [ 'gs_bucket_name' => 'myuserpics' ];
$upload_url =
CloudStorageTools::createUploadUrl('/upload_handler.php', $options);
I Use the above URL as the action for the form I use to accept uploads, as follows:
<form action="<?php echo $upload_url?>"
enctype="multipart/form-data" method="post">
Files to upload: <br>
<input type="file" name="uploaded_files" size="40">
<input type="submit" value="Send">
</form>
Below is the content of upload_handler.php:
<?php
var_dump($_FILES);
?>
I start uploading to the above URL within 10 minutes of its creation and get the following output:
array(1) {
["userfile"]=> array(5) {
["name"]=> array(1) {
[0]=> string(11) "fashion.jpg"
}
["type"]=> array(1) {
[0]=> string(10) "image/jpeg"
}
["tmp_name"]=> array(1) {
[0]=> string(200) "gs://myuserpics/***VERY LONG STRING***"
}
["error"]=> array(1) {
[0]=> int(0)
} ["size"]=> array(1) {
[0]=> int(59527)
}
}
}
The permissions set for the bucket "myuserpics" are the default permissions.
When I look in the bucket, I do not see the uploaded image.
From the Google Developers Console, I am able to upload an image and then see it in the bucket. However, if an image is uploaded from the app, I cannot see it in the bucket. What am I doing wrong?
回答1:
Did you call move_uploaded_file during the script execution to move the file from the temporary GCS filename?
At the end of the script execution, all of the temporary files (i.e. $_FILES['userfile']['tmp_name']) are garbage collected and removed from the bucket.
回答2:
The problem:
In my code, after an image is uploaded, I immediately display it and below it, present the user with a form into which to fill out the image title. After the user submits the form, I rename the image and store its new name and title into a database. This procedure has been working well for over a year until this week.
The solution:
As soon as an image is uploaded, I rename it before displaying it together with its associated form.
Conclusion:
A change has been made by either php or GAE that is causing "garbage collection" to occur much quicker than before. If this is not true, then why am I no longer able to wait until a user submits the form before renaming the image?
Note: I do not use move_uploaded_file as earlier suggested because I do not want to change the image's location.
来源:https://stackoverflow.com/questions/28663305/image-file-successfully-uploaded-using-a-google-app-engine-application-does-not