Accessing file contents from local hard drive using PHP

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?

Who is Participating?
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?

Marcus BointonCommented:
Roonaan is right (of course!). You might like to start here:

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

A question however would be:
Do you need access to yóur local drive only, or to any local drive?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.