travismoore Posted July 12, 2008 Share Posted July 12, 2008 I'm looking for a script that i can use to have files below the public domain on my server but still access them on my site. Mainly because I don't want other people downloading the content. thanks, Travis Quote Link to comment https://forums.phpfreaks.com/topic/114432-serverside-script-to-serve-up-files-from-below-public-on-server/ Share on other sites More sharing options...
wildteen88 Posted July 12, 2008 Share Posted July 12, 2008 PHP can access outside of the document_root. Use ../ to one level higher in the document tree, eg include $_SERVER['DOCUMENT_ROOT'] . '../secret/file.ext'; Say your directory structure is like this / (root) | +--home | +-- secret (where you files are) | | | +-- file.ext | +-- public_html (document root) $_SERVER['DOCUMENT_ROOT'] returns your sites document root ( eg /home/public_html/) Now the ../ tells PHP to go out of the public_html directory into the /home/ directory and load file.ext in /home/secret You can ofcourse use an absolute path. Quote Link to comment https://forums.phpfreaks.com/topic/114432-serverside-script-to-serve-up-files-from-below-public-on-server/#findComment-588449 Share on other sites More sharing options...
travismoore Posted July 12, 2008 Author Share Posted July 12, 2008 cheers will try that out =D Quote Link to comment https://forums.phpfreaks.com/topic/114432-serverside-script-to-serve-up-files-from-below-public-on-server/#findComment-588454 Share on other sites More sharing options...
travismoore Posted July 12, 2008 Author Share Posted July 12, 2008 Just tested it and it didn't work. It was probably something I did as I'm quite new to php. Here's what I tried: <?php include $_SERVER['DOCUMENT_ROOT'] . '../test/slayer.preview.jpg'; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <body> <a><img src="slayer.preview.jpg"></a> </body> </html> I uploaded it here and i just get errors: www.test.llamafiend.com/test.php Quote Link to comment https://forums.phpfreaks.com/topic/114432-serverside-script-to-serve-up-files-from-below-public-on-server/#findComment-588472 Share on other sites More sharing options...
wildteen88 Posted July 13, 2008 Share Posted July 13, 2008 You cannot serve images that are out side of your document root. Images on your site will always be downloaded locally to the users computer. There is no way to protect your images. Also the code I posted was only an example. What you're trying to do is not possible Quote Link to comment https://forums.phpfreaks.com/topic/114432-serverside-script-to-serve-up-files-from-below-public-on-server/#findComment-588869 Share on other sites More sharing options...
DeanWhitehouse Posted July 13, 2008 Share Posted July 13, 2008 you can look into javascript to load the image, after the page has loaded. Or use innerHTML to replace the image, protecting it slightly Quote Link to comment https://forums.phpfreaks.com/topic/114432-serverside-script-to-serve-up-files-from-below-public-on-server/#findComment-588873 Share on other sites More sharing options...
travismoore Posted July 13, 2008 Author Share Posted July 13, 2008 This was just to test it what I'm intending to do is load video into a flash player. Quote Link to comment https://forums.phpfreaks.com/topic/114432-serverside-script-to-serve-up-files-from-below-public-on-server/#findComment-588877 Share on other sites More sharing options...
discomatt Posted July 13, 2008 Share Posted July 13, 2008 you can look into javascript to load the image, after the page has loaded. Or use innerHTML to replace the image, protecting it slightly What? In order to view the image, the browser must download it... somewhere! This was just to test it what I'm intending to do is load video into a flash player. Huh? Same goes for above. If the user is viewing it, they're caching it. Quote Link to comment https://forums.phpfreaks.com/topic/114432-serverside-script-to-serve-up-files-from-below-public-on-server/#findComment-588974 Share on other sites More sharing options...
DeanWhitehouse Posted July 13, 2008 Share Posted July 13, 2008 i said some security, as the image url, will be shown as one image in the source code, but the js will load a different image, and nothing is stopping them stealing content, you can try a few js tricks, like no right click, but js can be disabled Quote Link to comment https://forums.phpfreaks.com/topic/114432-serverside-script-to-serve-up-files-from-below-public-on-server/#findComment-588978 Share on other sites More sharing options...
discomatt Posted July 13, 2008 Share Posted July 13, 2008 i said some security, as the image url, will be shown as one image in the source code, but the js will load a different image, and nothing is stopping them stealing content, you can try a few js tricks, like no right click, but js can be disabled You don't quite understand what I'm saying... The file is already on their computer. Masking stuff doesn't add anything. Quote Link to comment https://forums.phpfreaks.com/topic/114432-serverside-script-to-serve-up-files-from-below-public-on-server/#findComment-588988 Share on other sites More sharing options...
DeanWhitehouse Posted July 13, 2008 Share Posted July 13, 2008 u don't understand, it makes it slighty(ever so) to find out the url , as it won't be in the img tag Quote Link to comment https://forums.phpfreaks.com/topic/114432-serverside-script-to-serve-up-files-from-below-public-on-server/#findComment-588999 Share on other sites More sharing options...
travismoore Posted July 13, 2008 Author Share Posted July 13, 2008 I know its impossible to stop people from downloading the file but i want to make it as hard as i can. Quote Link to comment https://forums.phpfreaks.com/topic/114432-serverside-script-to-serve-up-files-from-below-public-on-server/#findComment-589083 Share on other sites More sharing options...
travismoore Posted July 22, 2008 Author Share Posted July 22, 2008 so what are these "tricks" i can use to make it harder? Quote Link to comment https://forums.phpfreaks.com/topic/114432-serverside-script-to-serve-up-files-from-below-public-on-server/#findComment-596701 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.