Hi guys

I'm working on my site, and I want to include this page
http://www.q8ieng.com/renders/index.php

the code inside (renders/index.php) is

<?php
if(@ini_set ( 'zlib.output_compression', 'On' )) @ini_set ( 'zlib.output_compression_level', 9 ); else @ob_start ( 'ob_gzhandler' );
require 'gallery.php';
?>

to my page this one
http://www.q8ieng.com/renders.php

I used to include it this code

<? include("renders/gallery.php") ?>

Note that: gallery.php is the main file for the script, as it is used to include in the index.php


and I ended up with this error

Could not open the cache directory.

What should I do guys? please help me, i'll be much more appreciated ^^

Dani AI

Generated

Short summary: the error almost always means the gallery script cannot find or write to its cache folder because relative paths change when a file is included from a different location. was right to worry about include paths, and hit the key point about the cache directory. ’s suggestion about parentheses is not the cause — parentheses around the include expression do not make PHP suddenly fail to open a directory.

Make the cache path absolute inside the gallery code so it always points to the right place regardless of which file includes it. A reliable pattern is to build the cache path from the gallery file’s own directory and then test for existence and writability. Example (put this in the gallery file, not in the parent page):

$cacheDir = dirname(__FILE__) . '/cache';
if (!is_dir($cacheDir) || !is_writable($cacheDir)) {
    error_log("Cache folder problem: $cacheDir");
    trigger_error("Could not open the cache directory.", E_USER_WARNING);
}

Confirm the directory actually exists on disk and has appropriate ownership and permissions. From a shell (or via hosting control panel) set ownership to the webserver user and avoid leaving it universally writable if possible:

chmod 755 /full/path/to/renders/cache
chown www-data:www-data /full/path/to/renders/cache   # or apache, nobody, etc. as applicable

Quick checklist: 1) ensure the gallery builds an absolute cache path (as above); 2) ensure the cache folder exists at that path; 3) confirm the web server user can write to it; 4) check PHP/webserver error logs for details. Also note the index file’s compression/ob handling can interfere when included into another script — move compression setup to the top-level entry script or guard it so it only runs once.

Recommended Answers

All 4 Replies

I don't know if this will help, but I noticed that your include may not be correct.
Try this <?php include("./renders/gallery.php"); ?>
or
<?php include("gallery.php"); ?>

I think you include would be trying to include (if your file is at ) www.yoursite.com/renders/renders/gallery.php. I could be wrong but that is what I saw off the bat.

I did tried all what u said but nothing is happened :(

I hope someone will figure out the problem where's it :\

Get rid of the parentheses and put a semicolon at the end. <? include("renders/gallery.php") ?> should be <? include "renders/gallery.php"; ?>

Your include is defined correctly, however there is a cache directory defined in your gallery.php. Your cache directory is located in /renders/cache and when you include the index file (which includes the gallery file), the script reads your cache file as being at So what you need to do is go into gallery.php and change your cache directory to /renders/cache/.

Hope this helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.