opening a file on local computer from website

General discussions related to php

Moderators: egami, macek, gesf

Post Reply
markcars
New php-forum User
New php-forum User
Posts: 1
Joined: Fri May 03, 2019 3:01 pm

Fri May 03, 2019 3:09 pm

I want to be able to open a text file on my local computer.
The php script is on the a webserver and trying to open a file using fopen is failing.

I have
$filename = "c:\test.txt";
before the fopen, I tried to use file_exists() by this

if (file_exists("$filename"))
{ echo "File exists OK!"; }
else { echo ("File DOES NOT exist");
}

Result is always "File DOES NOT exist!"

Can someone find the problem?
Thanks!

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 843
Joined: Mon Feb 22, 2016 5:52 pm

Sat May 04, 2019 2:48 am

If your webserver is on you local machine, you need to find the full path to it, I doubt that it is in your root (c:\), it is more likely to be something like

Code: Select all

C:\Users\(User_Name)\Documents

Where user_name is your computer user name,
Assuming you are using windoze and which version of windoesn't you are using.


If you can find the file in explorer, you should be able to right click or hold shift down and right click and then copy as path; paste this into your script.

If you have a remote server, then it doesn't make sense to allow it to access your computer at all, in any event, since that would open the door for anyone to access your computer, although it can be done - however - and no offence, I wouldn't advise you to do that as it is full of security risks. You would be better to transfer (a copy) of the file to the webserver.

Post Reply