Open txt file from desktop using PHP - php

It is possible to open a txt file from desktop to my webserver?
I have tried fopen but It cant open the stream.
Code:
$txtfile = fopen("C:\Users\steve\Desktop\AntiCheat.txt","r");
echo $txtfile;
The Error message:
Warning: fopen(C:\Users\steve\Desktop\AntiCheat.txt): failed to open stream: No such file or directory
This works fine If I using XAMPP but on my webserver it does not works

This works fine If I using XAMPP but on my webserver it does not works
XAMPP is a package that includes a web server, so presumably, you mean that it doesn't work if you use a web server that is running on a different computer.
This shouldn't be a surprise as the other computer won't have your hard disk in it, so it won't have your C drive or your files.
You need to either:
Share your file over the network to the computer running the web server (since the web server probably doesn't run on your LAN, this is likely to be logistically challenging).
Copy the file to the computer running the web server.

Related

.php downloads instead of opening in Chrome and FF

I'm using sftp to reach my folder on a server at uni. Both chrome and firefox would download my simple test.php instead of opening the page.
Is there any suggestion where should I look with the preferences to change this? (Ubuntu 16.04)
Oh, okay I understand it now, my bad.
I literally mounted the server to my local machine with ssh, thus I had no server whatsoever.
I had to reach directly with the url to open it, so I couldn't just open it from editor (VS Code - open with browser).
Your webserver isnt passing the php file to php for processing and is just sending it on as it would any other file. You will need to ensure that your webserver is setup to handle php correctly be it php-fpm for apache and nginx or the php module for apache
What's the webserver? You can start to read here: http://php.net/manual/en/install.php

php read contents of file on shared directory

I have a laptop running a server and I want to read a text file which is mounted on a raspberry pi. I have shared the Pi directory on the windows network and can access this folder ok. I have got a PHP script that can open a file on the localhost drive and display the contents, but I cannot get it to read from the shared Pi folders.
The following is a simple php script which is suppose to read the file and display the contents.
<?php
$data = file_get_contents('file:///Y:/test1.txt');
echo ($data);
?>
I can access the folder through the windows explorer so it has been shared correct. I can also see the contents of the file if I put the following in google explorer
file:///Y:/test1.txt
Is there a way to do this easily or i need to think of a different approach. I see others have tried this but cannot see how they have got this to work
I have read about having to change the reg file in the windows machine.
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters
RestrictNullSessAccess to key 0 which I have done but still does not work

Open directory on network in PhpStorm

I'm working from a windows 7 PC and my source code is on an Ubuntu PC. I have a shared folder on the Ubuntu computer that I can browse from my Windows computer.
I'm trying to open this directory in PhpStorm via File -> Open Directory. The problem is I can't seem to browse the network using the File browser (shown below) PhpStorm provides. Also entering a path like \my-dev-pc\projects\php\cms just causes it to open my C:\ directory.
Any ideas on how I can solve this? Perhaps some configuration that allows PhpStorm to use the default Windows Explorer file browser?
Since your project files are on network, you should follow below steps:
file > new project from existing source.
Then you will get a pop up with options for connecting to remote machine/server using ftp/sftp.
Select that and then enter your credentials.
There is also an option to select files which are accesile via network.
This should help you.

How to resolve linux folder name vs Win7 localhost folder name

I have a text file on my Linux website and I'm trying to run my website php code on my Win7 localhost machine.
The text file on the server is located at:
/home/vault/public_html/ssfiles/mysql.txt
On my local machine I'm running Apache/PHP/MySQL and my php files are located in:
C:\wamp\www\
How do I get my php script to open the file with the first folder string and to also work locally with the second folder string?
I'm new to running php on my local machine and have always run my php scripts directly on the Linux server...so I'm not sure how to resolve this?
Is there a php.ini setting that handles this? based on what machine the script is executing on?
Thanks...
If you place the files in htdocs folder in c:\wampp\ you can directly access the file with localhost/folder_name/file_name.php from broswer

PHP can't move (write) uploaded files to mounted network drive

We develop our PHP-based web applications by editing our working files in a shared, local directory on each of our windows machines. The (linux) staging server then mounts our shared drives and serves them each under subdomains. E.g. joe.work.com would serve Joe's working directory. We then access our own staging sites by editing our hosts file to point the subdomain to the staging server...and all of that works great!
We're now running into the issue that PHP doesn't seem to have permission to move uploaded files from the tmp directory to a directory inside of the mounted directory (which is actually the shared windows drive...?).
The working directory on the windows machines are set to allow everyone rw, and I have tried putting 777 on the mounted directory in the staging machine, but I am still get permission denied.
The shared drive, say, \\joes_machine\joes_working_dir mounts on the staging server to /var/mnt/joe. The file upload needs to be moved to /images/common.
Albeit slightly dumbed down for this example, I'm not doing anything fancy code-wise:
$working_directory = '/var/mnt/joe';
$image_directory = '/images/common/';
$full_filename = $working_directory . $image_directory . $filename;
if(move_uploaded_file($_FILES['photo']['tmp_name'], $full_filename))
// do some other stuff
My error of course is:
Message: move_uploaded_file(/var/mnt/joe/images/common/resulting_filename.jpg):
failed to open stream: Permission denied
Message: move_uploaded_file(): Unable to move '/tmp/phpjsEfBc' to
'/var/mnt/joe/images/common/resulting_filename.jpg'
What am I not understanding about file permissions pertaining to a windows shared drive being mounted over the network by linux and PHP needing to write to it? I can't seem to find the hang up!
Once we hit production, we won't be using the schema, but if there's a simple solution to be able to continue in our current development environment, then that would be ideal!
After a few hours of facerolling, I finally found what I was missing. The issue was that the credentials supplied couldn't write to the mounted directory as expected. The way I was able to fix this was by editing the mount command as follows:
mount -t cifs //shared/directory /mount/target
-o rw,username=connectionuser,password=password,uid=48
so, username and password are to be the windows credentials used to connect to the drive, but uid specifies the unique identifier of the local user on the staging server that apache runs as so that it may write to the mounted directory.
previously, i had not specified the uid of the local user, so when apache was trying to write to the mounted directory, it was trying to use the windows credentials (that couldn't write on the 'local' drive)
hope this is helpful!

Categories