Hi,

I must have done something wrong,
but I just can not see what it is :o

This is my code to open a file:
(I do this just before my cURL )

Strange thing is, my logfile opens fine, just the feeder.zip
gives me the problem.

$log_file = "/home/public_html/a_log.txt"; 
$handle = fopen("$log_file", "a"); 

$logstamp = date('H:i:s l, j F Y', $today);

$content = "----------------------------------------------- \r\nNew record - Time Stamp: $logstamp \r\n";
fwrite($handle, $content);  

$content = "This script: update.php, This file: $log_file\r\n";
fwrite($handle, $content);  

$target_url = "http://www.example.com/feed.xml.zip";
$userAgent = 'EasyDL/3.xx';

$file_zip = "feeder.zip";


$cef = "curl_err.txt"; 
$ceh = fopen($cef, 'w');

$content = "Target_url: $target_url\r\n";
fwrite($handle, $content);  

// make the cURL request to $target_url
$ch = curl_init();
$fp = fopen("$file_zip", "wb");

if ($fp === FALSE ) { 
  $content = "Problem opening $file_zip\r\n";
  fwrite($handle, $content);  
exit; }

So my log shows:

-----------------------------------------------
New record - Time Stamp: 02:03:34 Wednesday, 27 January 2010
This script: update.php, This file: /home/public_html/a_log.txt
Target_url: http://www.example.com/feed.xml.zip
Problem opening feeder.zip

Is there something wrong with:
if ($fp === FALSE ) ?

Can anyone see what I am doing wrong ?

Thanks

.

    I think either the filename is not correct
    or there is a file permission issue.

      So this bit is incorrect ?

      if ($fp === FALSE ) ?

      The Manual says:

      Returns a file pointer resource on success, or FALSE on error.

      So what would be the correct way to check for FALSE ?
      Does it need dots .FALSE.

      or in quotes 'FALSE'

      or something ?

      I have seen it in coding before somewhere.

      .

        I think that there's probably a permissions issue here. Relative to where the main script is being executed (if this is an included file), is feeder.zip in the same folder as the executing php script? If not, then the path to the file is wrong and needs fixing.

        If there is no path issue, then it's more than likely permissions. Is feeder.zip writable by the server? If not, it won't let you open it for writing.

        The last thing I notice is that it seems that you are wanting to add / edit a zip file's contents. There are better ways to do this. For one, you could use php's [man]zipArchive[/man] functions to do what you want probably.

          This script is run by itself.

          The file "feeder.zip" is being created in the same directory
          as the script and the directory has 755 permissions.

          The line: $file_zip = "feeder.zip";
          should create the file in the same directory if
          it doesn't exist shouldn't it ?

          Just to be clear ...

          is if ($fp === FALSE ) a valid test ?

          and is it the same as if(!$fp) ?

          .

            is there a line number where this error is hapening. there should be.

            Desmond.

              Thanks,
              I have now fixed my errors 🙂

              But if anyone knows the correct answer, I would still like
              to know the answer to my last question:

              is if ($fp === FALSE ) a valid test ?

              and is it the same as if(!$fp) ?

              .

                is if ($fp === FALSE ) a valid test ?

                and is it the same as if(!$fp)

                It is a valid test.
                And in this case !$fp can be used the same.

                But sometimes we actually have to test if ===FALSE
                For example if $x can be either 0 or FALSE
                and we want to know which.

                Here we can not use if(!$x) .... because it would always be true.

                  Write a Reply...