File created without content with PHP

Asked

Viewed 73 times

0

I have the XAMPP installed on a machine with Windows 8 Enterprise. Developing in PHP happens that when loading the page a temporary file is created in the folder C:\Temp having as content a given IP address.

$tmpfname = tempnam("C:\Temp","CCT_");
$handle = fopen($tmpfname, "w");
fwrite($handle, $circuito['loopback0']);
fclose($handle);

Renaming this temporary file to a default name.

$conn= rename($tmpfname, "C:\Temp\conecta.txt");

It is accessed later where this IP is read and used to make a connection by Telnet.

In my machine all this works fully, but when accessing the page of other machines, the file comes to be created with the default name, but without content (blank).

What could be causing this problem?

  • 4

    This problem has the face of invalid permissions, because the files created through the function tempnam are permitted 0600, where only the creator can read and write to the file. Once the file is being created but there is nothing of it, the machine should not be understand the network user as "owner" of the file.

  • there is some way to change the permission or other way to make this file be written by users who run?

  • 1

    Try to change the function tempnam by functions sys_get_temp_dir and file_put_contents, because in that case the files will be created with the permissions for other users to write to them. Or simply try to change the permissions with chmod before writing.

  • Unsuccessful also through file_put_contents, and by chmod($tmpfname, 0755) before grace also did not work.

  • This variable $circuito['loopback0'] doesn’t work just for a local connection? What are you actually trying to record in the file?

  • in this file an ip address is saved, for example: 10.76.0.50. This ip is the value of $circuit['loopback0']. On my machine everything happens right, the problem is when access by other machines (they are all within the same network/ domain)

  • What is the content of $circuito when you access the file remotely?

  • $circuit['loopback0'] is a field of my BD. after creating the file connects.txt, it is read by another remote access program, Teraterm.

Show 3 more comments
No answers

Browser other questions tagged

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