0

I'm looking for a way to save images stored in a MySQL database on a different server to a directory on the server I'm currently working with. I'm retrieving JSON data, and each entry displays a url that links directly to the image stored in the database. This is what I'm doing currently, with no success.

<?php
   $url = 'https://secure.example.com/app/api?accountid=000&apikey=000&action=getview&format=json&viewid=0000&tableid=0000';

   $ch = curl_init($url);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   $response = curl_exec($ch);
   curl_close($ch);

  $imageList = json_decode($response,true);

  $x = 1;

  foreach ($imageList as $imageItem) {
     $img = $imageItem['face_image'];

     echo "<img src='" . $img . "' width='150' height='200'/>"; //THIS WORKS, DISPLAYS IMAGES

     $dest_dir = "/uploads/"; //THIS DIRECTORY IS 777 CURRENTLY
     $src_file = $img;

     file_put_contents($dest_dir.$x.".jpg", $src_file);

     $x++;
}?>

1 Answer 1

3

Your desitination seems suspect: $dest_dir = "/uploads/" This means the root of the server ie. where bin,lib, etc. live, as opposed to the webserver's DOCUMENT_ROOT. You probably dont have permission to write there. Try:

$dest_dir = $_SERVER['DOCUMENT_ROOT']."/uploads/"

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

Comments

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.