Connect to SQLite database located in Google Drive from PHP - php

I think the question says it all. Since PHP5 we have a lot of methods for SQLite database handling. Now I have uploaded a SQLite file to my Google Drive Folder and granted read and write access for all to it. Is it now possible for me to connect to this database file from PHP with functions like:
$dbconn = sqlite_open($googleDriveLink); // or
$db = new SQLite3($googleDriveLink);

Read and write access in the context of google drive, means "read and write using their User Interface or APIs", on the other hand, PHP needs "Operating System's read and write access" to the file. Google is not exposing the file in a way that SqLite can handle it. The most best that perhaps in a tricky way, you can obtain is a download and an upload of it, but will collide with others and wont be useful.

You may want to educate yourself on Google Drive's API reference, specifically its section about Files.
You could pass it the download URL, as I assume that's what you mean by $googleDriveLink, but I don't think that's what you're looking for. Say, for example, privacy settings on the file are changed that don't allow anonymous downloads.
To take advantage of the Google Drive APIs in PHP, you'll need to leverage an HTTP client in your code that handles the communication, that or create a backend that your PHP code uses. It may be beneficial to read the Google API PHP Client Library's getting started document.
In whichever path you choose, you'll more than likely have to download the SQLite file to your PHP server and manipulate it locally, and then optionally update it on Google Drive.
Hope that helps.

Related

error while using file operations in google appengine

) i am creating a php application in google appengine. Since i will have to pay for the cloud sql, i decided to use some files instead of the sql database and read/write from it. but the problem is i am not able to create or modify the existing files using php's standard file operations like 'fopen' and 'fwrite',etc. when i run the same code in 'localhost:8080' it is working properly. but not in the uploaded version in internet. i am getting errors while creating/writing to the files. please help. thank you
You should read the appengine php runtime docs https://developers.google.com/appengine/docs/php/#PHP_The_sandbox
Specifically the section about the sandbox. The crucial statement -
An App Engine application cannot:
write to the filesystem. PHP applications can use Google Cloud Storage
for storing persistent files. Reading from the filesystem is allowed,
and all application files uploaded with the application are available.
This was a while ago, but if you still want to write to file system, you can write to the gs cloud
https://cloud.google.com/appengine/docs/php/googlestorage/#writing_files_from_your_app
you need to add the bucket to your php.ini file
google_app_engine.allow_include_gs_buckets="yourapp.appspot.com"
and make sure your Service Account Name has permissions to edit the cloud storage
HTH

How can I use Dropbox as a host for uploaded files using PHP?

So I am working on a small website with some simple admin area. In the admin area it should be possible to upload/download/update files of a global directory. The problem is that my php programs don't have write permission to the server and the size limit of the database is 100mb which is not enough. Therefore I thought it would be nice to store the files in a dedicated Dropbox account or something.
My questions are:
Would it be reasonably easy to code a web-interface to this Dropbox account in PHP?
Are there any alternatives to Dropbox for this purpose?
Any other ideas how to handle this situation?
Edit: My problem with Dropbox is that it's API uses OAuth. But since I want to connect to one global account for all users instead of each users account this seems inappropriate and I don't even know if the authentication is possible this way. All the links mentioned use this API and therefore need user authentication through a redirect.
Yes you can use the dropbox account. Try out the PhpDropboxUploader. Its also mentioned in the dropbox Wiki
require 'DropboxUploader.php';
$uploader = new DropboxUploader('email.address.used.to.log.in.to.dropbox#example.com', 'dropbox-password');
$uploader->upload('file-to-be-uploaded', 'destination-folder-in-dropbox');
for your first question, there is indeed a PHP SDK that is not official but still listed on dropbox site :
https://www.dropbox.com/developers/reference/sdk
and
https://github.com/BenTheDesigner/Dropbox
btw, are you sure you can't make a directory for which PHP has write permission ?

Zend_Cloud_Storage how to send files to browser?

I'd like to store my asset in the cloud. I thought Zend_Cloud_Storage may be the right library? For now they are saved locally using Zend_Cloud_StorageService_Adapter_Filesystem. Upload works so far.
What is the right way to send files from Zend_Cloud_StorageService_Adapter_Filesystem to the browser? I guess this is only possible by streaming them through php? If yes any code examples out there because I have problems getting it working with all the file header.
Using S3 I probably would make a redirect or directly link the files to the s3 bucket?
I'm pretty new to cloud storage so I really appreciate your help.
Kind regards, Manuel
The Zend Cloud services are fairly new and from my experience the documentation still needs a bit of work. Depending on the cloud service, you have either the choice of fetching your objects and delivering them to the user or in some cases you can give the user a direct URL to the asset (this largely depends on if you need to control access to the object).
To fetch an item programmatically, you should be able to get it to work with right header, for example:
$image = $storage->fetchItem("/my/remote/path/picture.jpg");
header("content-type: image/jpg");
echo file_get_contents($image);
In theory you can get the content type for the header from the metadata, but I'm not sure if it is consistent between adapters.
Linking directly depends on your Cloud. For the filesystem you should know the path to where your files are, so you can link from there if they are accessible. In Amazon, you can set the permissions to public when you upload the file - there is an example in the S3 doco here.
I'd recommend having a look at the Zend Service S3 doco, Zend Cloud is just a wrapper for it and in trying to be generic it looses a lot of functionality. if you work with it for any length of time I suspect you'll eventually end up doing calls straight to the service.
Good luck!

Online file storage logic

I want to develop a website like file manager. Where user register and will get fix disk space lets say 20MB.
Now user can upload their pdf, doc, txt, jpeg etc files upto their disk limit.
I can develop upto this using PHP.
Now below is my issue:
1) If user's files are corrupted they can rollback their folders before 2-3 days.
Files must be secure and safe from viruses as users are uploading their important documents.
Is there any 3rd party storage server who provides such facility?
2) Also all files should be previewed from browser.
I am using Google doc viewer. Is is good and safe way to preview file in browser?
But google links are accessible from all, I need to add some restrictions as file can be viewed only by their owner.
I know it's a major task, but i just need some sort of logic. Please share your thoughts.
Thanks.
Any cloud storage service can be used for this. You'll get HDD space. There is not storage server who provides revision control system for this. You can use git, svn for this though. But as the files are binary you can not get full facility of these tools.
How file will be previewed depends on you. If you use PHP you make the site and at the backend you use the API to interact with the storage service. Google doc is not an option for this if you use PHP. Also note Google links can be made private.
I suggest you this,
Find a cloud storage service and use the storage in your server. Any will do.
Create UI using PHP and control the access using PHP too.
Manipulate files in your server directly or in 3rd party storage server via API
Use a revision control system to track the changes. And use its API in PHP end.
Some cloud storage service
Amazon S3. It also supports Versioning.
Google Cloud Storage
Microsoft Azure
Try Microsoft SkyDrive or Google Drive or Dropbox

Writing files in a Google Chrome extension

I am currently developing my own Google Chrome extension right now. My extension has the functionality to save and retrieve user data(bookmarks, browser preferences) from a local storage in a computer. Right now there are tools and technologies I am considering to use for the development of the said extension. Which brings us to my question:
I know for sure that PHP can be responsible for the file handling which includes storing and retrieving of browser data. My concern is that the security of the written file. Is it possible to put the written text file in a folder which is locked? Is it possible to make that folder account-controlled meaning for the folder to be accessed there should be username and password to be entered? What tool or technology can handle this?

Categories