Need some help in downloading pics from a website - php

I am looking for some help in downloading pics from a website. Here is the problem detail.
URL is basvandenbroek dot com,
suppose when we visit the following page http://www.basvandenbroek.com/nl/product/27341/704/snaarinstrumenten/boston/snarenset_elektrisch.html
we have a thumbnail pic here which when click bring its larger version. I would like to capture the larger image using a php script and download it onto my pc.
Problem is when we inspect the HTML we see the following code for images
../../../../../../../jpg/27000/27341.jpg
../../../../../../../jpg/cache/27000/220_220_27341.jpg
Based on the above code i assume that if i append website address at the start of the
jpg/27000/27341.jpg I could access the pic but its not working it that.
I believe URL is hidden or I might not understanding things properly. I am new to PHP and Scripting and I would like somebody to help me through it situation.
Thank you

For the website you mentioned, if the thumbnail is
http://www.basvandenbroek.com/jpg/cache/27000/220_220_27341.jpg
then the
http://www.basvandenbroek.com/jpg/27000/27341.jpg
So the thumbnail is basically the dimensions (220 x 220) added as a prefix to the original in a different folder. Also, there is nothing like hidden URL. Any link that is valid on a web-page is sure to appear in the source of the html. In chrome and firefox, atleat, you can find this link by right-clicking the link and copying the link address.
In your case you can find the thumbnail's url by right-clicking the thumbnail and the original's url by right-clicking it.
However, if you want to do this automatically using PHP, you will have to write code that can parse the html for the page to determine the urls.

In your example, here would be the larger image:
http://www.basvandenbroek.com/jpg/27000/27341.jpg
The smaller image is at:
http://www.basvandenbroek.com/jpg/cache/27000/220_220_27341.jpg
This means you would need to scrape out the first two underscored parts of the name (220_220) using string manipulation. You would also want to string replace "cache/" with an empty string.

relative urls are relative to the url of the containing document. so if the document you're scraping is located at http://example.com/foo/bar/baz/doc.html, and the image is referenced as
../../omg/wtf/lol/cat.jpeg, its full url is http://example.com/foo/bar/baz/../../omg/wtf/lol/cat.jpeg, or http://example.com/foo/omg/wtf/lol/cat.jpeg.
btw, this has nothing to do with PHP or scripting in general, and is instead firmly a HTTP thing. and there are no "hidden" URLs in HTTP, that would be a contradiction.
edit: your comment makes it look like the problem is with the Referer header or session id sent (or not) in your request.

Related

How to save webpage with all styles and images similar to evernote?

If you look at evernote or use their web clipper browser addon, it can save a webpage completely with all styles and images of page clipped. So for example if I save this very page with it, it will be saved as is.
Does any one have an idea of how evernote does it? I want to do it with either PHP or JavaScript but am not sure how to save a webpage with all styles and images. I know about Internet Explorer's mht format but that's not what evernote does.
So basically it would be great if one can save a webpage with all styles and images (excluding dynamic content such as JS) in single file and be able to open it in any major browser ? Any pointer to such script would also be helpful.
I have also noticed similar thing in Gmail, when you copy any part of page and paste that in Gmail Compose, it renders it as it was or same happens in MS Word too.
Thanks for your help and hints :)
Replace linked stylesheets with style blocks containing the CSS copied from the linked stylesheets. Replace image sources with data URLs.
Or just shell out a call to wget -mk and mirror the site:
<?php
system('wget -mk http://foo.com/bar');
?>
You could do file_get_contents() and then go and recursively download whatever scripts/images you need.

PHP Using imagegrabscreen

How could I use imagegrabscreen to get a thumbnail image and a full size image of a specific website.
I was thinking that I could have an array that I feed the wanted uri's into but I am a bit stuck on how I would set the wxh of the image I need to grab. I also think that I would need a thumbnail class and a fullimage class and call them when required.
Any better Ideas?
Keep in mind that imagaegrabscreen is Windows-only. If you have multiple displays set up, this function will only grab the primary display. Also, for this to work, your Apache service must be set to Allow service to interact with desktop otherwise you will just get a blank image.
This discussion covers the use of imagegrabscreen pretty well: Getting imagegrabscreen to work
There are a lot of other discussions about saving webpages as images, too - here are a few:
Website screenshots
Web Page Screenshots with PHP?
How can I generate a screenshot of a webpage using a server-side script?
PHP: How to capture browser window screen with php?
What is the best way to create a web page thumbnail?
Screenshot of current page using PHP
shell tool which renders web site including javascript
In any languages, Can I capture a webpage and save it image file? (no install, no activeX)

Hiding image URL

Using shadowbox, I am displaying my images onto the screen like this:
<img src="images/thumbpic.jpg" width="100px" />
However I am looking for way to mask the image so that the URL path is not displayed. Otherwise the user will be able to access the image directly, by typing the URL into their address bar.
How can I do this?
This is not possible at all, since it's all client side and there's always a way to get that image. Same answer is for CSS & JS.
Disabling a hotlinking wouldn't help you, since this case has nothing to do with it (because you said by typing the URL into their address bar).
You could embed the image directly in the page. You then can't hotlink it and it would only be accessible from that page.
Here's an example: http://www.sweeting.org/mark/blog/2005/07/12/base64-encoded-images-embedded-in-html
Though, I don't believe this is supported on all browsers yet.
To prevent direct access to the images you should restrict the access to the images rather than trying to hide their URL.
To do this you can, for instance, modify your .htaccess file (a tool to generate an .htaccess file for this purpose can be found here).
In any case remember that the user can always (no matter what you do) save the images on his computer, you cannot prevent that, as the image is downloaded on the client when he visits your sites.

Masking or hiding the path to a background image

I'm displaying pieces of an image in a large grid created from divs. I'm using the background-image and background-position to display portions of the image. The problem I'm running in to is that a user can simply open up firebug and see the entire image (which defeats the purpose of the game).
I've attempted to mask the path using a php script as the URL but if the user navigates to the php file, they can still see the image. It would appear that anything I do with the CSS is entirely client side so denying everything outside the localhost in my .htaccess won't work.
Any suggestions?
The over arching goal is to have an automated way to split and display pieces of the image into a grid.
If you deliver the whole image to the browser, the browser holds the image and has every right to show it to a user. I don't think you can prevent the browser from showing it. I'm afraid you will have to deliver the image in pieces, or perhaps write your whole game using <canvas> and play around with images as pixel data. :)

Image Preview using AJAX in PHP

How should i create a preview of image to be uploaded before it is actually submitted using AJAX in PHP?
Without uploading the image, this is going to be impossible in JavaScript as far as I can see, because security limitations are going to prevent you from determining the selected file in the file upload, and embedding that file in an img tag (as it used to be possible five years ago.)
You will be more lucky with Flash-based uploaders. I have seen some that offer the kind of functionality you want.
Update: Here's one that offers a preview function. From what I can see, it base64 encodes the local image and serves it to the surrounding HTML page as a inline data <img> tag. This is great because it might integrate well into your site. It does not work with any version of Internet Explorer, though.
Here's a fully Flash based solution that does previews in all browsers.
you first have to upload the document to server. Than you can show like.
<img src="uploads/file1_12224.jpg" />
The "file" input type doesn't expose the local file location of the file to be uploaded. It does "appear" to because as a user you can see the location, but the web page never knows this value. Without the local file address, you can't show a preview of the image on the web page using plain HTML or JavaScript.

Categories