Accessing file contents from local hard drive using PHP

Posted on 2006-03-20
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?

Question by:nikez2k4
    LVL 49

    Accepted Solution

    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?

    LVL 1

    Expert Comment

    LVL 25

    Expert Comment

    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!
    LVL 17

    Expert Comment

    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

    LVL 49

    Expert Comment

    A question however would be:
    Do you need access to yóur local drive only, or to any local drive?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    6 Experts available now in Live!

    Get 1:1 Help Now