1
votes

I'm making my first PHP Google App Engine application using Google Cloud Storage.

I have a form with few upload fields in it. Once I upload an image using one field and keep the rest empty, a junk file is made inside my cloud storage bucket for those field which I did not upload any image. This is how my form look like

<form method="post" class="admin" action="<?PHP echo $postUrl; ?>" enctype="multipart/form-data">
<input type='file' name='image1'>
<input type='file' name='image2'>

<input type='submit' name='submitBttn' value='submit'>
</form>

I get $postUrl using CloudStorageTools::createUploadUrl method. Which works fine and once the form is submitted a var_dump($_FILES) displays values in the field which I uploaded and the empty one with empty values which has a error code of 4 which means a file is not uploaded using that field. How ever a junk file is made in my Cloud Storage bucket with a unknown image.

How do I stop this happening? If it cannot be stopped, how do I delete it from the bucket? ($_FILES['image2']['tmp_name'] and $_FILES['image2']['name'] are empty, so I don't know how to get the publiUrl without knowing the image name).

Thanks!

1
This definitely seems like an issue and I reproduced the problem. I have filed a bug report internally and will followup.boombatower

1 Answers

2
votes

Looks like two legitimate bugs: 1) all temporary uploaded files should be unlinked (deleted) if not moved (default mechanism does not work since it uses system unlink which does not handle gs:// since defined in user-space), 2) in PHP empty files are not written to temporary directory, but cloud storage proxy defaults to creating them so the App Engine PHP runtime should be updated to remove them.

Per documentation, http://www.php.net/manual/en/features.file-upload.post-method.php:

The file will be deleted from the temporary directory at the end of the request if it has not been moved away or renamed.

Working on fix and hope to have it in the next release.