So I know that I can retrieve the youtube thumbnail by going here:
http://img.youtube.com/vi/BoVBdxftEF8/0.jpg
obviously the ID changes based on the video. I want to write a script that I can get save the photo from that URL to a folder say called 'video_thumbnails'. Is there a somewhat simple way of doing this in PHP?
Quite simple:
file_put_contents ("video_thumbnails/thumb.jpg",file_get_contents("http://img.youtube.com/vi/BoVBdxftEF8/0.jpg"));
Related
My question is about HTML and PHP.
This is my setup right now:
A website where user have accounts
A FTP server with pictures (currently none)
Files are currently saved on the website in the "PICTURES" folder (which is accessible by everybody who know the full URL)
So, I would like to know how I can display the images without storing them on the website (which will fix my URL problem).
My idea was to move the files on the FTP server, and when a users logon and request a page with those images, download them through a FTP connection, save them on the website, display the images, and remove them. Which would make them accessible only between the downloading time. But this solutions sounds REALLY bad to me.
You need always to have a place where your images are stored. But, if you don't want to give a user the chance to know where are stored, you can create a system which is used to show the images.
Think about this, if you want to download a file from Mega, you can't access to the URL where the file is stored, instead of that, the server itselfs calls a system who assign you a "key" and you can download the file only through that system using your "key".
You could use a system like "base64" so you can encode your image, and show it using it, or, you can use the "header" modifier so, you can display an image using a PHP code.
For example your image tag will be like:
<img src="processImage.php?id=01&user=10&key=123" />
So, your processImage will return a "tricky" image, actually not the image, but the code processed by PHP will be returned, like using "imagejpg()" function with the header "Content-Type:image/jpeg" and then the user will not know where the image is stored actually but the img will works actually.
I want to output a file from Dropbox onto my website with Dropbox PHP Core SDK. To give an example, I upload an image to Dropbox. Now, how do I display that image to my website from Dropbox's servers. Keep in mind, I don't want to download this file from Dropbox and then display that image. Is it possible to display an image or another file directly from Dropbox using Dropbox PHP Core SDK?
EDIT:Would you mind being more clear on #1
How do I use the custom URL?
Can I do this: header("location: $url);
Is this how you use the custom url? Thanks!
Using the PHP Core SDK, the main way of accessing file content is using the getFile method, or for images where you don't need the full resolution, the getThumbnail method. However, these return the data directly, e.g., to save on your server and serve back to the user, so that doesn't suit your needs as described.
It sounds like you'd prefer the API to return a link to the image that you can use as the source for the images in the HTML of your page. The Dropbox API doesn't offer a method particularly well suited for that, but there are some non-ideal options:
1) You can use createTemporaryDirectLink to get a direct URL to the image. Note that these links expire after four hours though.
Using it would look like:
list($url, $expires) = $client->createTemporaryDirectLink("/default.png");
2) You can use createShareableLink to get a preview URL for the image. These links don't expire. Note that these don't link directly to the image data though, so you'd need to modify them as documented in this help article.
Using it would look like:
$url = $client->createShareableLink("/default.png");
Also, not that both of these are subject to bandwidth restrictions, per this help article.
I want a help,I created a facebook app using php gd.The program is when user open the app a image will appear.The image contains the username of the user,the profile pic and random generated nick name.Iam saving the output image to the server as resized.jpg and post that image to the users wall using facebook graph.
The problem is when 2 users use the app at same time,the output varies.
How to generate image to each user without saving it to the server and post to facebook.
now iam using html img tag to display the image in app..
Answer is quite simple: your image file name must have different names per user. If you have user id in $uid variable,why don't you save target file as:
imagejpeg( $rImg, "resized".$uid.".jpg" );
This way you'll have different images per user.
Rather than saving the file to your server as "resized.jpg", what you want to do is to output the generated image directly to the user. From http://php.net/manual/en/function.imagejpeg.php it says to set filename to NULL, which causes the output to be sent to the user instead of to a file. Note: you may also need to set the correct Content-Type using the header function.
This method is an alternative to Tomasz's. With his method, each image is cached on your server. With mine, the image is generated each time the page is requested. Here is an example showing the difference:
<img src="http://example.com/resized1234.jpg"> #1234 is the user's id
<img src="http://example.com/generate-image.php?uid=1234">
In your case, you said you are posting the image directly to Facebook, so I would advise my method, as Facebook will store its own copy of the image if you post it on their site, and won't need to be cached. Also, you won't have a other user's images piling up on your site.
Let me know if you need me to clarify anything in my answer!
My app is posting to users' Facebook walls, and linking to a page they have created. The page is in html. I'd like to be able to put a thumbnail of the page as the image on the wall post. I'm not sure whether this is possible or not. Anyone have any ideas?
If it helps, the page itself is stored as a series of 'elements'... for each one, I know the size and position of the element, and the content (which may be text or an image). So I can pull all that in from the database.
I guess it would be sufficient to create a thumbnail using php at the point when the user clicks 'Publish This to my wall', if that's easier than doing it on the fly - I can save the image and then link to it.
Any ideas?
I create thumbnails for my site using CutyCapt, which works very well indeed on both Windows and Linux. You can use exec to invoke this from php.
There are also web services that allow you a quota of free thumbnail snapshots, that are easy to integrate into your website. e.g.
http://www.websnapr.com/
or
http://webthumb.bluga.net/home
I figured out how to do this. I used the PHP gd library, which allows you to create a base image and then add images and text. Works pretty well.
In my project, user will upload videos. So i have done simple code to check video file extension and moved to a particular folder. now problem is that only registered user can see that video. So i decided to check session while loading page which contain player to play video. but in view-source option , video file url available. so then can see that video using that url. now i need to check session before accessing that video folder. or is it possible to store video files in DB?
thanks in advance..
It is insane, you need to make a rewrite or something like this video.php?id=blablabla, a then check if user is logged in, if he is, play (readfile) video. What type of file is it?
$id = $_GET["id"];
if($session == true)
{
header("Content-type: video/flv");
readfile("my/secret/path/".$id);
}
everything that's shown for a user can always be copied and spread, but one way to prevent it from a more regular user would be using a php that reads an id/hash(basicaly a key of some sort) that is related to an video and then loads the video through file_read and outputs it.
store key and then the real url in a database then query the id to get the real url and then use a file reading function for example to stream it
the function could be fopen, fgets or something similiar