0

I have three lines of code;

$image->saveAs('tmp/page.png');
$image = 'tmp/page.png';
unlink('tmp/page.png');

I would like to have a random filename for page.png, so I have chosen to use the following;

uniqid()

How would I go about using uniqid() within each of those three lines. So it appears as;

$image->saveAs('tmp/randomfilename.png');
$image = 'tmp/randomfilename.png';
unlink('tmp/randomfilename.png');

The full page code is;

<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

?>

<?php

$loader = require __DIR__ . '/vendor/autoload.php';

?>

<?php

use mikehaertl\wkhtmlto\Image;

$image = new \mikehaertl\wkhtmlto\Image('https://www.google.co.uk/search?q=what+is+the+time&oq=what+is+the+time&aqs=chrome.0.69i59j0l5.1536j0j4&sourceid=chrome&ie=UTF-8');
$image->setOptions(array(
'binary' => '/usr/local/bin/wkhtmltoimage',
'type' => 'png'
));

$image->saveAs('tmp/page.png');

$image = 'tmp/page.png';
$imageData = base64_encode(file_get_contents($image));
echo '<img src="data:image/png;base64,'.$imageData.'">';

unlink('tmp/page.png');
die();

?>

Edited by Mister_1

3
Contributors
2
Replies
25
Views
4 Months
Discussion Span
Last Post by jkon
0

The simplest solution could be to create a db table for your images (or files generally) first save a row in that file that has an auto increment id and then save it with that id

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.