You are here: Re: difficulties with include and writting to files « PHP Programming Language « IT news, forums, messages
Re: difficulties with include and writting to files

Posted by Mark Rees on 10/31/13 11:28

> root/index.html
> root/php/hitcounter.php
> root/php/hits.wordpad
> root/php/browser.php
> root/includetest.php
>
> hitcounter.php:
> <?php
>
> require_once('browser.php');
> $br = new Browser;
>
> $filename = 'hits.wordpad';
....
> ?>
>
> includetest.php:
> <?php
>
> $path = './php/';
> set_include_path(get_include_path() . PATH_SEPARATOR . $path);
> include ('hitcounter.php');
>
> ?>
>
> If I open my browser and directly go to
> http://.../root/php/hitcounter.php everything works fine. The file
> gets appended with my IP and browser information as it should. If I go
> to http://.../root/includetest.php I get an error output "The file
> hits.wordpad is not writable". This is odd because that particular
> error message only appears in hitcounter.php ... so I know that that
> code is executing. But yet, that code never has a problem executing
> when I visit the php file directly.

The problem here is most likely the path to the file. Let's say the file you
want to write to is in

/root/temp/

If you are trying to write to this file from a file in /root/ then the path
is simply temp/file.txt.

However, if you are in /root/php/, the path is ../temp/file.txt

To get around this problem, take a look at
http://uk2.php.net/manual/en/function.realpath.php
as well as dirname and a few other related functions

>
> Lastly, assuming someone can get this solved for me, my next question
> is about including the hitcounter in an html document. I was thinking
> the following would work:
> <?php
> include 'php/hitcounter.php'
> ?>
> However, when I tried this with a similar script, it appears to do
> nothing and I can view the page source of my html file and see the php
> code (shouldn't the server replace that block before sending the html
> file out?)

IIS or Apache?

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация