how can i access folders like
\\10.200.0.3\some_folder
user name: user
password: pass
is it possible to map network device then access it using php?
please help me connect to this share and access files there..
Try one of these;
Make sure the IIS worker process has access to that location (IUSR or IIS_IUSRS)
Change the website's application settings in IIS to use credentials from a user account who has access to the location
Since you will be running PHP using IIS/Apache user make sure server user also has permissions to access network shared folder. Once you are sure IIS user does have permissions to access shared folder, you may try listing contents of shared folder by using path such as:
$target_path = '\\\\server\\images\\';
Have a look at this questions, might be helpful:
PHP: upload files to network shared folder
What you're looking for is Server Message Block (SMB) or the open source implementation SAMBA.
To use this in PHP, you could look at smbwebclient.
You might however simply add a drive map to the share on your Windows server, assign it a fixed letter (like Z:) or even simply access \\hostname\folder (escape the backslashes) and use the PHP built in directory commands to read and write the files from that drive. It'll be a helluvalot easier.
Related
Hi I have build a script that downloads files from ftp account and then import data from them. However it works on localhost as after downloading files I save them on c drive and then read the files from there and process them. I need help to do this on live server. How can I achieve this and where can I store the files on server outside public_html folder.
I would really appreciate if someone can help me please. Thank you.
Yes, it will be good to store the files outside public_html
You can create download folder outside public_html using various tools. Log into you host provider account and use file manager tools there or else you can get an SSH credential for the host and create the folder using some SSH client
Also give proper permission to the folder, so that we can write/ read from it.
You can refer the location of the download folder from script using the script $_SERVER['DOCUMENT_ROOT'] .(Replace public_html with down load folder name)
this is not a very specific question, but sounds like you need to check permissions on your download folder on the server, set permissions so that your script can save into it, and you may want to keep it outside of public_html so that it is not accessible via the web server?
For example save it in public_html/../ftp (just illustrating the path here).
I have a php script on my webhost, GoDaddy, and I want to modify a text file. But it gets blocked, I think it's a problem of authorization but I don't know how to solve this.
<?php
$var= "test";
$fileopen = fopen("file.txt", w+);
fwrite($fileopen,$var);
fclose($fileopen);
?>
Apparently the issue is not with PHP but with the access control management on the server. You don't tell us the error you get, but I guess that you are denied write access to those files. Check the rights of the corresponding files and directory on your server and tweak them as needed to let the web server process access those files.
How to do it is very much dependent on the server's operating system, on the identity under which the web server process is running and on the kind of administrative rights you have yourself. Without further information, it is difficult to say more. Your provider must have some kind of documentation about how you can set up directory and file access rights.
I need to copy a file from one computer to another computer which is connected to lan network. I have IP address of that two machines. I have used code like this to achieve it ,
$file = 'file.text';// inside htdocs folder
$newfile = '\\\\192.168.1.15\\htdocsfolder\\';
if ( copy($file, $newfile) ) {
echo "Copy success!";
}else{
echo "Copy failed.";
}
but copy failed. How to debug, why file is not copied to another computer htdocs folder? whether i need to change share access on both computers?
Please help.
Thanks
You seem to be on a windows machine. Here are a couple of things to keep in mind and check for (which are a variation of the same theme):
If this is a scheduled task/batch job, try executing it from the terminal and check any errors you might get (beware of relative paths):
C:\> path-to-php script.php
Otherwise, if you can, run it as the webserver's user and see below:
Webserver process needs to have write access to \\192.168.1.15\htdocsfolder and read access to htdocs folder.
Check the user your webserver process runs as. Use your favorite process/task/service manager to check for the exact username and see if this user has the required access modes.
If you are in an Active Directory environment give access to the username identified above
If OTOH you are in a LAN, make sure the username exists (is a valid user) and has the same password on both machines.
If you do this right, permissions for Everyone are not necessary (and usually a bad thing)
Not to pick on MS and Windows, but do make sure about shares and permissions from "Manage my computer" -> "System Tools" -> "Shared Folder" as specified by Microsoft
Debugging is hard, you'll have to do a lot of further research on your own, Google and SO are your friends.
please check that the user executing php script has the access on remote file system.
If scripts are executed on Linux, its useful to mount remote share.
Just to add, your code worked fine with my case.
Is it possible to check for a directory on a users computer without knowing the directory? I want to write a php program that allows me to look at my skype photos, but every computer has a different file directory, based on the account name on the computer. File Directory:
C:\Users\compUser\AppData\Roaming\skype\Pictures
I'm looking for a similar function where; if we were to make the run command on a windows pc, you can type %appdata%\skype\pictures and have the file directory pop up.
PHP is a server side language, it can only browse the files on it's own server.
You can't access to local user pc directory for security motivations, you can access only to server directory (where php run)
PHP is a server side language, it can only browse the files on it's own server.
and you cannot access any file from computer to php server without input
I have a PHP web application running on IIS, which allows a user to upload a file from a simple html form. The uploaded file is then moved to a folder on another server. This is working correctly on Apache, but fails on IIS with the error:
function['move_uploaded_file']failed to open stream: Permission denied
in...
I've checked all the permissions on the directories. If I run a simple PHP script through the command line to copy a file from the server into the folder on the other server it works correctly, so I suspect the problem is with IIS.
if (move_uploaded_file($_FILES ["file"] ["tmp_name"], "\\\\000.00.0.00\\tia\\web\\upload\\" .$_FILES["file"]["name"])) {
This has been covered already here. Quoting the reason here:
You have mapped target directory to a share such as \server2\files. These mappings are only available to the current users (eg, the admin account), not to the IUSR account that your php is probably running as (assuming IIS). Solution, don't use mappings, instead use the full 'unc' path name, ie '\server\share\folder\file.ext', also remember that the IUSR account will need access to these shares/folders/files
From what I can see in your comment, you are using a \\ prefixed network share as the target for your move_uploaded_file() operation.
I'll bet a beer that PHP isn't allowed to access that share. Remember, PHP runs with IIS's permissions!
Try saving to a local, globally writable path first. If that works, you know you have to fix the share's permissions.