fopen, write

  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

hey, here is my code

PHP Code: [ Select ]
 
<?PHP
 
 
 
$filename = 'http://dhost.info/gmforum/rethink/install/blank.php';
 
chmod('$filename', 0777);
 
 
 
$fp = fopen($filename, "a+");
 
 
 
$string = "hi";
 
   
 
   
 
$write = fputs($fp, $string);
 
//now close the file
 
 
 
 
 
fclose($fp);
 
 
 
echo '<div align="center">
 
       <table width="60%" border="0" cellspacing="0" cellpadding="0" style="border:1px #000000 dashed;">
 
         <tr>
 
           <td><b>Files set up</b></td>
 
           <td align="center" width="40%"><font color="#003399"><strong>Successful!</strong></font></td>
 
         </tr>
 
       </table></div><br>';
 
     
 
      ?>
 
 
  1.  
  2. <?PHP
  3.  
  4.  
  5.  
  6. $filename = 'http://dhost.info/gmforum/rethink/install/blank.php';
  7.  
  8. chmod('$filename', 0777);
  9.  
  10.  
  11.  
  12. $fp = fopen($filename, "a+");
  13.  
  14.  
  15.  
  16. $string = "hi";
  17.  
  18.    
  19.  
  20.    
  21.  
  22. $write = fputs($fp, $string);
  23.  
  24. //now close the file
  25.  
  26.  
  27.  
  28.  
  29.  
  30. fclose($fp);
  31.  
  32.  
  33.  
  34. echo '<div align="center">
  35.  
  36.        <table width="60%" border="0" cellspacing="0" cellpadding="0" style="border:1px #000000 dashed;">
  37.  
  38.          <tr>
  39.  
  40.            <td><b>Files set up</b></td>
  41.  
  42.            <td align="center" width="40%"><font color="#003399"><strong>Successful!</strong></font></td>
  43.  
  44.          </tr>
  45.  
  46.        </table></div><br>';
  47.  
  48.      
  49.  
  50.       ?>
  51.  
  52.  


now i want to make sure that the file "blank.php" is writable... i then want to put in the word "hi".

So i chmod the file to 777 , but when i try to look in the file, it is still blank.[/php]
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

I don't know if fopen allows for reading via HTTP.
Try a relative path rather than absolute.

PHP Code: [ Select ]
 
$filename = "install/blank.php';
 
 
  1.  
  2. $filename = "install/blank.php';
  3.  
  4.  
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

PHP Code: [ Select ]
 
//create the file to connect to database on all pages
 
 
 
$filename ="../req/connect.php";    
 
               
 
 
 
$myFile= fopen($filename,'w+');    // Open the file for writing
 
//-------
 
if(! $myFile){            
 
 
 
echo '<div align="center">
 
       <table width="60%" border="0" cellspacing="0" cellpadding="0" style="border:1px #000000 dashed;">
 
         <tr>
 
           <td><b>Creating Files</b></td>
 
           <td align="center" width="40%"><font color="#cc0000"><strong>Failed!</strong></font></td>
 
         </tr>
 
       </table></div><br>';
 
} else {
 
 
 
echo '<div align="center">
 
       <table width="60%" border="0" cellspacing="0" cellpadding="0" style="border:1px #000000 dashed;">
 
         <tr>
 
           <td><b>Creating Files</b></td>
 
           <td align="center" width="40%"><font color="#003399"><strong>Successful!</strong></font></td>
 
         </tr>
 
       </table></div><br>'; }
 
//------
 
fputs($myFile, $string);    // Write the data ($string) to the text file
 
 
 
fclose($myFile);        // Closing the file after writing data to it
 
 
  1.  
  2. //create the file to connect to database on all pages
  3.  
  4.  
  5.  
  6. $filename ="../req/connect.php";    
  7.  
  8.                
  9.  
  10.  
  11.  
  12. $myFile= fopen($filename,'w+');    // Open the file for writing
  13.  
  14. //-------
  15.  
  16. if(! $myFile){            
  17.  
  18.  
  19.  
  20. echo '<div align="center">
  21.  
  22.        <table width="60%" border="0" cellspacing="0" cellpadding="0" style="border:1px #000000 dashed;">
  23.  
  24.          <tr>
  25.  
  26.            <td><b>Creating Files</b></td>
  27.  
  28.            <td align="center" width="40%"><font color="#cc0000"><strong>Failed!</strong></font></td>
  29.  
  30.          </tr>
  31.  
  32.        </table></div><br>';
  33.  
  34. } else {
  35.  
  36.  
  37.  
  38. echo '<div align="center">
  39.  
  40.        <table width="60%" border="0" cellspacing="0" cellpadding="0" style="border:1px #000000 dashed;">
  41.  
  42.          <tr>
  43.  
  44.            <td><b>Creating Files</b></td>
  45.  
  46.            <td align="center" width="40%"><font color="#003399"><strong>Successful!</strong></font></td>
  47.  
  48.          </tr>
  49.  
  50.        </table></div><br>'; }
  51.  
  52. //------
  53.  
  54. fputs($myFile, $string);    // Write the data ($string) to the text file
  55.  
  56.  
  57.  
  58. fclose($myFile);        // Closing the file after writing data to it
  59.  
  60.  


heres my new code..... it comes up as "FAILED".
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

check that the path to the file is correct and the file is writable[/php]
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

how would i do it, if..... its like this..

DIR

INSTALL - REQ


install and req are on the same path if you get me... so i will need to go back one then go in to req and get the "blank.php".
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

where is the file that is running the script sitting?

gimme an example like
http://domain.com/dir1/req/connect.php = file to open
http://domain.com/dir1/script.php = file running script
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

ok...

http://www.domain.com/folder/folder/file1.php < thats what im running from.

http://www.domain.com/folder/req/file2.php < is what i want to fopen
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

at the top of the page enter
PHP Code: [ Select ]
 
error_reporting(2047);
 
 
  1.  
  2. error_reporting(2047);
  3.  
  4.  


tell me if anything come up
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

nothing shows.
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

Can you write into a php file? I always thought it had to be a .txt.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

You can write to any file if it has a text based format. Thinking about that, I wonder if you write the binary data, of say an image, and say it with the correct extention - would it work? Gonna go find out now.

Think it is only ASP you can only handle txt documents

Post Information

  • Total Posts in this topic: 11 posts
  • Users browsing this forum: No registered users and 121 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.