Find file on server

Asked

Viewed 1,001 times

4

Good afternoon, I have a PHP file that looks for a txt to take the information and go up the SQL database, but this file is generated by the server here in the company (where my machine is already mapped to R: or Adm server).

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

But I wanted to leave this "automatic", where my PHP program already looked at the server directly without having to play on my machine.

Today I use the fopen (ATUALIZA.txt, r)", to open the file, and it works normally. I’m getting this error when using the server walk: fopen (\\servidor\adm\atualiza.txt):failed to open stream. permission denied in blá blá blá.

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

  • 1

    Have you checked if the user that PHP is running has access to this server folder and the share?

  • I checked. This local server is used for internal file shares. I have full access over such folder. I have permission to read, change and delete the file.

  • You have this page: http://support.ultimatelocator.com/index.php?/Knowledgebase/Article/View/60/0/php-Session-problems-Warning-session_start-opentmp-failed-permission-denied Check if you have followed the steps correctly. Sometimes it is permission in the folder, on the server, or the folder path in the source. Att, André.

2 answers

3

I’m sorry I don’t put that as a comment, but I still don’t have the reputation for it...

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

Take an example:

<?php
// 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 might as well do something like:

<?php
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 ?

  • I couldn’t use this function. I think it might be some problem with the network, because if I do with the local file, it works, but when I enter the address of the server it does not understand the path. The server is configured for any user to use the files, full permission to all(I changed to perform the tests)

  • The use of a file .txt is mandatory ? XML - See examples.

0

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

For PHP documentation, you can use the command copy(), that it will copy a source to a destination.

copy ( 'R:\ATUALIZA.TXT' , 'c:\pata_do_wamp\seu_site\ATUALIZA.TXT' );
  • Jesus, why use the shell_exec ? This is a function that when used carries too many risks if not employed properly.

  • The command didn’t work for me in this case. If I run the DOS command it works, copy the file normally, but by php it does nothing.

  • @Edilson as you said yourself, se não for bem empregue, I believe that this use will not cause harm or risk to the system.

  • @Edilson, got better using the copy function()?

  • @Matheusdelatorre if I’m not mistaken, the function shell_exec() is disabled by default. E @Franciscocabral function copy() serves to copy a file from one destination to another, and what the user wants, is to get the data in that file.

  • @Edilson He had said that he could open the file if he moved the file manually to the directory of the site, so I searched for the fastest solution, copy the file.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.