$file_name = $_FILES['filetoUpload']['name'];
$temp_name = $_FILES['filetoUpload']['tmp_name'];
$type = $_FILES['filetoUpload']['type'];
$options = array('gs' => array('entity' => 'allUsers', 'role' => 'READER', 'acl' => 'public-read', 'Content-Type' => $type, 'contentEncoding' => 'ANSI'));
$context = stream_context_create($options);
$publicFileText = date('ymdhis');
$fileName = "gs://<bucket-name>/" . $file_name;
file_put_contents($fileName, $publicFileText, 0, $context);
$publicUrl = CloudStorageTools::getPublicUrl($fileName, TRUE);
Hi Tejashree,
In the statement: “$options = array('gs' => array('entity' => 'allUsers', 'role' => 'READER', 'acl' => 'public-read', 'Content-Type' => $type, 'contentEncoding' => 'ANSI'));”
The ANSI value does not seem right. Content-Type can be “Any valid MIME type”, for instance “text/plain”. You describe your saved content as an image, not text. You may consider looking closer to the way this metadata is set. If somehow only text gets saved, and not the intended image, your file size would appear small, just as you describe it here.
The statement: “ $publicFileText = date('ymdhis');” seems to indicate a text file as well, storing a date.
What are the steps you have undertaken to finally store the image with the help of your PHP program? Any relevant detail might help, and information from logs, and the like.