Cache facebook/twitter profile image - php

I want to let the users upload their facebook/twitter profile picture as an avatar. I insert a record with their token/secret in the DB. I've made a script that gets the user's id and displays the profile image using readfile() but I want to cache this image for 30 minutes. Is this possible with codeigniter?

Although not codeigniter specific.. On a site I created - when the user logs in with facebook, we download the file using something similar to file_get_contents.. we then store our local reference to it along with a MD5 of the image data.. This allows us to easily check whether we need to update our local store when the profile is next requested (this does require the server to re-download from facebook)
In other instances, we store the file size that facebook reports, so that we can do a HTTP HEAD request to check easily if its changed (I realise size doesn't have a direct relationship to the image changing.. however 99.9% of the time its a good indication.

Related

Android app how to get photos of a specific user

I'm creating a social app similar to instagram on Android studio.
Users will be able to upload and view photos in this app.
The photos are saved on a Cloud in a folder called "ProfileImage" and the URL of the photos is saved on the MySql database, along with the ID of the photo and the user's ID.
To get the photos I would like to use Picasso.
If for example the user A wants to look at his photos, the app will have to show him only his photos, that is I will have to get the URLs of the photos that have the id of the user A.
Picasso to get the photos use the following code Picasso.get().load("http://i.imgur.com/DvpvklR.png").into(imageView);
But the problem is that I don't know the specific URL of the photos.
One solution I thought of is to get the URLs of the photos via PHP and pass them into an android variable that I will use as a URL variable for Picasso.
But this solution seems slow to me, in the sense that the photo will not be displayed immediately, but seconds will have to pass.
Can anyone recommend a faster and perhaps better solution than mine?
First of all, Upload your image to server and save image url inside mysql database not image itself. Create one api that returns user info including image url.

How to save a file in a hidden location php

I have to build an application where users can download videos from a site but cannot share them. My first solution is to save these files in a hidden location on the users computer since one of the requirements is that the user should be able to watch the downloaded videos offline.
Please how do I go about saving a file in a location the user cannot see using php.
Thanks.
One solution is to generate token for each request for a video. That token would have its lifetime. Php script should be serving the content instead of giving direct access to resource to user. The script should check if the token is still active before serving the content.
It is up to you how to pass the token. The simplest way is to make it contained in uri.
No matter where you put your videos in your directory structure, you always send the data as a partial request. Once data is acquired by the user, it could be saved an reproduced.
There are techniques, however, to protect your video from direct download through curl, wget or other ways of download. And this is using a secure token and an expiration, passed as parameters. This way your video download window will be limited and generating the token manually would be pretty hard.
Chidiebere Onwunyirigbo, its a Great Question. One solution for your requirement is Steganography. It is the process of concealing your data (videos) behind other files (multimedia files like image, audio, video), in your case preferable would be Image Steganography. It is quite a old technology but new to many, you can get several ready tools/code for it on the internet which you can customize as per your need. From your side you have to provide the file that is already embedded inside the image for download. Only the tool coded for retrieval and rendering the hidden video can render your video. So, for this part all the users of your site have to first download this desktop application from your site for viewing the video. This will keep your videos safe on the users computer offline, because every user who takes the video will require the reverse steganography tool to be downloaded from your site. You can even embed secret info like users IP inside the Stego image along with the video and for each tool download, associate user computer's IP with the tool. If IP embedded inside Stego image matches with that of tool only then you allow to play else redirect application to get it registered. But the limitation would be that, the users will have to download your application and will be able to view videos only on your desktop application which will render the Steganographed video.
You cannot hide information on the user computer. Even if your process are running on a windows comp as SYSTEM user, a power user can take ownership of the files.
The only solution you have, are developing or using a known DRM system, for allowing only playing the video on a determined computer or another specifications (for example, if the program have the authentication token of some user).
At any case, you need to do two things for this:
- You need a custom application to play the video, if you want to check DRM.
- You need to recode / modify something on the video before download, for adding on them a code for allow only play on the destination computer or data used for authenticating DRM.

Cloudfiles API with SNET set to true seems very slow

So I did as suggested here.
But I'm still seeing some pretty slow responses when getting URLs for files stored in containers on cloudfiles.
The application I'm building has a portion where users can comment. Each user has a profile image which shows up next to their comment. The basic structure of the code is as follows:
1) Authenticate cloudfiles api
2) Open connection
3) Retrieve main users profile image
4) Retrieve all comments from database
4.1) Loop through users comments
4.2) Get container and file name from DB
4.3) Retrieve image from CloudFiles
5) Close connection
I have SNET as true and I am on a Rackspace server but, it seems to crawl in comparison to when I stored them directly on the server. Also the reason I am not storing the public url in the database is due to the user being able to change their image and me wanting to store past images, therefore not overwriting the past image. I could store each past image's url as well as the new images and probably will do that but, wanted to see how fast I could get it prior to doing that.
The reason I am hesitant to go straight to storing each images public url is because on another portion of the site I am going to use Temp URLs for some secure files and am trying to see if I can fix the performance in general.
Any suggestions are appreciated!
Thanks

Workflow for photo upload with login and photo display online

Hello I am working on an educational app just for my own learning where a user can login, upload photos, and then have them display on a website. I am a little confused on the general idea of how it should work. I know this isn't the best place for this type of question but I can't find it anywhere else.
Basically I want a user to be able to login with something like OpenID and then upload a photo ( I am using phonegap and thus they would use the Phonegap API to do this and I understand the mobile side here ) to a server and then have be hosted on the server and be able to have a user's photos displayed together.
Do I need to have each photo be submitted to a database and if so how would I store the photo info? If you have any input it would be appreciated I am a little lost. I know php for the server side I just don't know what to do.
Do I need to have each photo be submitted to a database
Only if you want to, you would have the base64 encode it or store it as a blob though. Your best bet would be to store the image somewhere on your server outside of the database and instead store its address or path in a database along with a unique ID.
how would I store the photo info?
What photo info, the exif data? Or are you talking about additional general information? (date it was uploaded, user that uploaded it, etc etc) Either way, you would make a column in the database table for each chunk of data you want to store.
For example, if you wanted to store the date each photo was uploaded and which user uploaded it, you would set up columns in such a way that a row in the database that look something like this:
(columns) id photo user date
(row) 58 uploads/img58.jpg myuser192 1338483324
as for actually getting the photos on your server, perhaps you could use an html5 friendly solution like Uploadify

Auto generate PHP page for Facebook open graph

I'm trying to build an app on Facebook where users can upload their images, share it on their wall and get their friends to 'Like' their photo.
I'm not pretty sure how to do it, I have a page where a user uploads their picture and I would like them to have their own page upon picture uploaded so that their Facebook friends can 'Like' it.
Can I have 1 page with values or do I need to auto generate for each users?
This is like a Photo Contest.
You could use mysql database to store the data and call it using php when you want to see it, you will only have to create on page, and can automatically update itself when someone uploads a new picture, send to facebook and then store that data into the database so that it can easily be referenced again.

Categories