We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


Accessing file contents from local hard drive using PHP

nikez2k4 asked
Medium Priority
Last Modified: 2008-02-01
Hi guys,

I am trying to load the contents of a txt file into a variable so I can store them on my server. The thing is I don't know how to access the file which is on my PC using a PHP script on a server.

I have a form with a file upload box which, when submitted, posts to a PHP page. I then have taken the output from the upload box - C:\\text_text.txt - and stored it in a variable.

From there I have no idea - I need to be able to open that file (on my pc NOT the server) and read it's contents.

Any ideas?

Watch Question

Top Expert 2006
You cannot, unless you install a ftp-server or other way php is allowed to access your filesystem.

What is the problem with just uploading the file?


Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Roonaan is right (of course!). You might like to start here: http://www.php.net/manual/en/features.file-upload.php

I guess you could turn it around and run a web server on your PC and let your server pull whatever it wants from your PC. You might have a few, erm, security issues with that though!
The only solution would be:
- set up dynamic DNS for your home machine
- set up a minimal apache (or lighttpd or other 'tiny' webserver) off a hidden port on your box.
- mod firewall(s) to allow the connection from your server (fixed IP? if so, use that specifically to filter!) back to your http server.
- make the ONLY thing in local httpdocs be your text_text.txt file
- use CURL or other file-retrieval to get http://your.dyndns.dom/text_text.txt

Top Expert 2006

A question however would be:
Do you need access to yóur local drive only, or to any local drive?
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.