Find file on the server

Posted on

Question :

Good afternoon, I have a PHP file that looks for a txt to get the information and upload it to the SQL database, however this file is generated by the server here in the company (where my machine is already mapped to R: or server adm).

Today I have to go to R: , get this file ( ATUALIZA.TXT ), bring it to my machine in the WAMP folder, where the PHP file is, and then I’ll run the file.

But I wanted to leave this “automatic”, where my PHP program already searched the server directly without having to play on my machine.

I’m getting this error when I use the server path: fopen .

Can anyone help me find a solution on how to open this file on the network ??
Thank you.


Answer :

Sorry for not putting this as a comment, but I still have no reputation for such …

I had a similar problem in the company where I worked, where PHP created the file on the server but did not create it with the read permissions due, the solution I found was to change the permission of the file soon after its generation, with the command chmod , solved my problem.

See an example:

// Escrita e leitura para o proprietario, nada ninguem mais
chmod ("/somedir/somefile", 0600);

// Escrita e leitura para o proprietario, leitura para todos os outros
chmod ("/somedir/somefile", 0644);

// Tudo para o proprietario, leitura e execucao para os outros
chmod ("/somedir/somefile", 0755);

// Tudo para o proprietario, leitura e execucao para o grupo do prop
chmod ("/somedir/somefile", 0750);

The function chmod returns true or false, and in your case you could do something like:

if(chmod("ATUALIZA.TXT", 0644)){
  //instruções para lidar com o ficheiro

Another thing is, why use .txt if there are options like JSON and XML ?


Since the shell_exec() function is very dangerous to the system, here is another function that can solve your problem.

By PHP documentation , you can use the command copy() , which will copy a source to a destination.

copy ( 'R:ATUALIZA.TXT' , 'c:pata_do_wampseu_siteATUALIZA.TXT' );


Leave a Reply

Your email address will not be published. Required fields are marked *