Member Avatar

I have three lines of code;

$image = 'tmp/page.png';

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


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

$image = 'tmp/randomfilename.png';

The full page code is;


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



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



use mikehaertl\wkhtmlto\Image;

$image = new \mikehaertl\wkhtmlto\Image('');
'binary' => '/usr/local/bin/wkhtmltoimage',
'type' => 'png'


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



Recommended Answers notes this fails for your needs. Read hackan's reply to see it returns same value (or string) when called too quickly.

That could create some very hard to trace bugs.

Jump to Post

All 2 Replies

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

Be a part of the DaniWeb community

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