Problem with php and batch


I already set apache so that PHP can execute .bat files, I have to move files from another server to my computer to do operations with it, when I execute the batch manually if I do the function, but at run it from php no longer, I can say that I have another batch that moves a local file to another local route and when executed from php if I perform the action.

Batch that connects to a server:

Copy "\\respaldos\proyecto_bboo\error.txt" 

php that executes it:


When printing the error it says Acceso denegado . I must put the file batch in a special path or what else I have to configure in my php.ini .

I already tried the solution that they gave me below and even then it does not work I leave capture of the batch and when executing the batch from the php

asked by sanlegas 03.04.2018 в 02:33

1 answer


In php to execute a bat file you must write the exec with the cmd command executable and the corresponding parameters, for example:

exec('C:\WINDOWS\system32\cmd.exe /c "C:/xampp/htdocs/caet/copi2.bat"');

For the part of the remote copy, the copy command you are using over the SMB protocol, your Explorer is probably already logged in with username and password for the connection to the target computer, but your PHP environment and apache most likely will not. is it so. It could probably work to log into the SMB from the bat file in the following way:

net use "\\respaldos" /user:"usuario" "contrasena" /persistent:no
copy "\\respaldos\proyecto_bboo\error.txt" "C:\xampp\htdocs\caet\error.txt"
net use "\\respaldos" /delete /yes

In the first line you are logged in to the smb of the remote computer, there you have to put the user and the password that you use to log in, if there is no part of the password and user, the second line is your original copy, and the last one is to desloggearte.

This is a bash executed on my computer correctly with the password and the network path and permissions on the necessary folders:

answered by 03.04.2018 в 05:16