0

I'm trying to cache an users look from an external website and cache it locally in the same folder. I've come up with this so far:

    <?php
  $figure = $_GET['figure'];
    $action = $_GET['action'];
    $direction = $_GET['direction'];
    $head_direction = $_GET['head_direction'];
    $gesture = $_GET['gesture'];
    $size = $_GET['size'];
    $imgFile = "$figure$action$direction$head_direction$gesture$size";
    $imagesPath =  $imgFile;

    if(!file_exists(($imagesPath))) {

        $otherSiteUrl  = "http://sourcewebsite.com/image/look?figure=$figure&action=$action&direction=$direction&head_direction=$head_direction&gesture=$gesture&size=$size";
        file_put_contents($imagesPath, file_get_contents($otherSiteUrl));
        }

 header("Content-Type: image/png");
        readfile($imagesPath);

    ?>

This worked for a while until today. I am not sure why. It just returns a broken image icon.

13
  • 1
    What debugging methods have you tried so far? Does the file_exists($imagesPath) return true? Or is it requesting the image? If it's requesting the image, are you getting any content returned in the file_get_contents? Commented Jun 6, 2013 at 14:24
  • You might have run out of space, meaning you can't create a new image. Commented Jun 6, 2013 at 14:28
  • @Pudge601 I tried the CLI and logging so far, what other methodes are recommend Commented Jun 6, 2013 at 14:31
  • @Sami Dz Hamida I have enough space left on the harddisk (>800GB) Commented Jun 6, 2013 at 14:32
  • 1
    @user2460028, they're fine, important thing is, we need to know what output you're getting, and what's happening, if we're going to solve this. So as far as my previous questions go, what have you been able to determine? Commented Jun 6, 2013 at 14:34

1 Answer 1

0

Firstly, it may be necessary to specify a directory in which to save these image files, rather than the current directory of the script that's running. For example, you could save them in a subfolder for the images, so the images path would become;

$imagesPath = dirname(__FILE__) . '/imageCache/' . $imgFile;

This would require you to create a directory called "imageCache" in the directory where your script is located.

Next, you should set the permissions on this directory to allow your script to write a file into it. See http://technet.microsoft.com/en-us/library/bb727008.aspx for Windows, or http://www.dartmouth.edu/~rc/help/faq/permissions.html for unix (mac and linux).

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, Thanks a ton. I moved my wwwroot folder to a different partition and of course the CHMOD settings didn't move. I used CHMOD on my folder and the script worked again. Thank you once again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.