How to make the code write information from multiple files?

0

I have a code to create watermark on each image that was uploaded. At the end of this code, I would like every time a person uploaded the image, a record was created in a notebook. I came to this code but I'm having a hard time getting it to keep track of multiple uploads.

$arquivo = "rastro.txt"; 
$data = date("d/m/Y H:i:s");   
$ip = $_SERVER['REMOTE_ADDR'];    
$browser = $_SERVER['HTTP_USER_AGENT']; 
$fp = fopen($arquivo, "w+");   
fwrite($fp,"Nome: $new_name | Data: $data | IP: $ip | Navegador: $browser");   
fclose($fp);

How do I loop the code?

    
asked by anonymous 30.12.2015 / 12:35

1 answer

1

The problem is how you open the file. With w+ you open the file for read and write plus puts the recording pointer always at the beginning of the file. This causes you to always overwrite the file data, giving you the impression that you have only recorded once.

Consider using a or a+ because it opens the file and places the write pointer at the end of the file.

$arquivo = "rastro.txt"; 
$data = date("d/m/Y H:i:s");   
$ip = $_SERVER['REMOTE_ADDR'];    
$browser = $_SERVER['HTTP_USER_AGENT']; 
$fp = fopen($arquivo, "a+");   
fwrite($fp,"Nome: $new_name | Data: $data | IP: $ip | Navegador: $browser \n\r");   
fclose($fp);
    
30.12.2015 / 13:04