Last active
June 5, 2022 15:34
-
-
Save imselmon/b54b2593e2e0138aa8b4c5643863170a to your computer and use it in GitHub Desktop.
PHP Upload file in Google Cloud Storage & Firebase Storage using Firebase PHP SDK
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require __DIR__.'/vendor/autoload.php'; | |
use Kreait\Firebase\Factory; | |
$storage = (new Factory()) | |
->withServiceAccount('Service-Account.json') | |
->withDefaultStorageBucket('storage.appspot.com') | |
->createStorage(); | |
$bucket = $storage->getBucket(); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="" method="POST" enctype="multipart/form-data" name="ex_card" class="forms-sample"> | |
<div class="form-group"> | |
<label>College or University Logo</label> | |
<input type="file" name="education_img1x" class="file-upload-default"> | |
</div> | |
<button type="submit" name="Add_education" class="btn btn-primary me-2">Update</button> | |
</form> | |
<?php | |
session_start(); | |
include 'config.php'; | |
if(isset($_POST['Add_education'])){ | |
if($_FILES['Education_img1x']['name']){ | |
$bucket->upload( | |
file_get_contents($_FILES['Education_img1x']['tmp_name']), | |
[ | |
'name' =>"Education_img".$_FILES['Education_img1x']['name'] | |
] | |
); | |
} | |
?> |
how will i retrieve na name of the files i have uploaded sir?
how will i retrieve na name of the files i have uploaded sir?
Send a get request to this URL, it will give you an json with items if your storage
https://firebasestorage.googleapis.com/v0/b/coder-salman.appspot.com/o/
Response
/coder-salman.appspot.com/ -> replace with your own bucket URL
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It Needs the Firebase PHP SDK