I am trying to protect my upload of images to a PHP script, and the last hurdle I have to fulfill is that users cannot directly exclude images, but the server can still serve them on web pages. I tried to change ownership and folder permissions to no avail, so I am trying to save images above public_html and display them on pages that are stored in public_html.
My file structure:
- userimages image.jpg image2.jpg - public_html filetoserveimage.html
I tried to link the image to the userimages folder as follows:
<img src="../userimages/image.jpg">
But that will not work. Is something missing here? If you have any suggestions, please let me know. I am trying to get public users to execute potentially dangerous files that they could download. As well as an additional safety measure. Thanks!
You want something that is basically impossible.
The way the browser loads the page (in the main sense):
Step 1: Download the page. Step 2: analyze the page. Step 3. Download everything that is indicated in the content of the page (images, style sheets, javascripts, etc.).
Each Download event is atomic.
, , , .
PHP Jedi, PHP. HTTP_REFERER , "" .
PHP passthru script , .
, , - "hotlinking" - , . , , .
, , mod_rewrite .
hotlinking/anti-hotlinking
script!
, public_html, php script. , image-relay.php, , html...
<?php header('Content-Type: image/jpeg'); $_file = 'myimage.jpg'; // or $_GET['img'] echo file_get_contents('/myimages/'.$_file); ?>
$_file $_GET, absolutley ...
<img src="image-relay.php?img=flower.jpg"> flower.jpg, /myimage/flower.jpg...
<img src="image-relay.php?img=flower.jpg">
, - public_html.
public_html , Apache , / dorectory.
public_html
, Apache, / public_html.
, , <img>, - , -, src URL- .
<img>
src
, , .
, (php ) script, , IP-, , html- ( , , IP-) ( HTTP-, , ).
, ( <img>, ), public_html (php ) script, .
If you use Apache or lighttpd, you can use the X-Sendfile header to send files that are not in the root directory of the website (provided that you have not changed the configuration of the mod_xsend file).
To learn more about the X-sendfile, see this site .
This solution gives you the best performance since PHP does not send the file, but the server does it, and therefore PHP can be deleted while the files are running.
Hope this helps.
Source: https://habr.com/ru/post/1717530/More articles:Removing Subversion User - authenticationКак определить, работает ли какой-либо конкретный процесс приложением WPF или нет? - processas3 Events - Type of coercion failed? - eventsWhy do I need it. does the qualifier use the extension method on the main page? - .netПлатформа Symbian OS S60 - mobileСтруктура модульной структуры по умолчанию для приложения Zend Framework - directoryBash - $ PATH and $ {PATH} - bashMVP vs. Presentation Model, which one is better? - design-patternsSubsonic ActiveRecord and Foreign Key Property Names - .netCreating a packed binary representation of a file set? - c #All Articles