store them in DB $dir = scandir("../data/"); foreach ($dir as $i) { echo "$i\n"; if ($i != "." && $i != "..") { $reply = json_decode(file_get_contents($this->baseurl . "search/movie?api_key=" . $this->apikey . "&query=" . pathinfo($i)['filename'])); if ($reply->total_results == 0) { // no results found // todo maybe parse first pictures somehow } else { echo json_encode($reply->results[0]); $image_base64 = base64_encode(file_get_contents($this->posterbase . $reply->results[0]->poster_path)); $image = 'data:image/jpeg;base64,' . $image_base64; // Insert record $conn = Database::getInstance()->getConnection(); $query = "insert into Movie(name,url,poster) values('" . pathinfo($i)['filename'] . "','/data/$i','" . $image . "')"; if ($conn->query($query) === TRUE) { echo('{"data":"successfully created entry"}'); } else { echo('{"data":"' . $conn->error . '"}'); } } } } } } $bla = new Movie(); $bla->reindexMovies();