• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 520
  • Last Modified:

Have coding using fopen, fwrite, but webhost no longer allows

Hiya,

Below is the index file of an open source program I'm trying to install in a folder of my website. My webhost doesn't allow the fopen function (and I would guess that includes fwrite, but I've no idea about "touch"). CURL is enabled on the server, but I can't quite get it to do everything.

Alternatively, I figured that all perhaps all this does is create and write an .htaccess file containing the line:
php_value include_path "/export/home/webhost2_c/www.epigenome.org.uk/WWW/CMS/phpcg/app/settings/"
Naturally all I get are 500 - internal error messages. Aargh!

<?php
      $path_parts = pathinfo($_SERVER['SCRIPT_FILENAME']);
      $ROOT = $path_parts['dirname'];
      $ROOT = $ROOT."/app/settings/";
      $filename = ".htaccess";
      echo $ROOT ."<br>"; // me testing
      // $ROOT is /export/home/webhost2_c/www.epigenome.org.uk/WWW/CMS/phpcg/app/settings/
      
      if (!file_exists($filename)) {
         touch (".htaccess");
         $fp = fopen($filename, "w") or die("Couldn't open $filename");
               fwrite($fp, "php_value include_path \"".$ROOT."\"\n");
               fclose($fp);
            
               include("install.php");
            header( 'Location: index.php' );
      }
?>

Server info is:
Apache/2.0.58 (Unix) mod_ssl/2.0.58 OpenSSL/0.9.8d DAV/2 PHP/5.1.2 mod_jk2/2.0.2
--with-curl=/usr/local/include/curl' '--with-curlwrappers' '
.htaccess is enabled

Would really appreciate any help. Servers are a bit of a black box to me and I've been playing with this for far too long.
0
Ekorn
Asked:
Ekorn
  • 4
  • 4
1 Solution
 
GawaiCommented:
http://www.php.net/fopen

If PHP has decided that filename specifies a local file, then it will try to open a stream on that file. The file must be accessible to PHP, so you need to ensure that the file access permissions allow this access. If you have enabled safe mode, or open_basedir further restrictions may apply.
0
 
hujiCommented:
Also if fopen is disabled on the server, you cannot use fwrite any more. It means, if the people who run the server have disabled fopen, there is no way for your script to work (that I know of).
0
 
EkornAuthor Commented:
Thanks for replying but, erm, I think my question was unclear. I'm aware that the Server Gods will not allow the fopen/fwrite at all. What I'd like to know is if/how I can/should:

a) replace this bit of code with a CURL (or something):
    touch (".htaccess");
         $fp = fopen($filename, "w") or die("Couldn't open $filename");
               fwrite($fp, "php_value include_path \"".$ROOT."\"\n");
               fclose($fp);

or b) write an htaccess file myself the way the file intends, without an .htaccess error

or c) toast the app and get something else.

The software programmer isn't responding to the questions on the SourceForge forum.

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
hujiCommented:
a) CURL allows "reading" but not "writing". This mean, you cannot use it instead of your current code.

b) Yes, you can create the htaccess file manually.

Cheers,
Huji
0
 
EkornAuthor Commented:
That's helpful Huji, I can focus on the .htaccess file. Why the heck would a file containing only the line:
     php_value include_path "/export/home/webhost2_c/.../WWW/CMS/phpcg/app/settings/"
cause an error!?


0
 
hujiCommented:
because this one line is causing PHP to try to load files from a location, which may not exist. Make sure that address (/export/.......) really exists on your machine.
0
 
EkornAuthor Commented:
Hmm ... as far as a I can tell it does, in fact exist. I'll ask the Server Gods for log error files on Monday.

Otherwise, if the rest of the app doesn't require constant .htaccess updates, I may be able to just substitute php.
0
 
hujiCommented:
Make sure that setting in .htaccess is needed for the rest of the code to run. If not, don't even add it.
0
 
EkornAuthor Commented:
Discovered several pages of this code are dependent on fopen and fwrite, so I'm just going to toast it for now.

Thanks for your help, all.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now