0

Im generating Identicons using a php script. Showing the result using a <img> works fine

$input="create_image/identicon.php?size=48&hash=$hashvalue";
$output=$username."_userimage.png";

This works:

echo "<img src='$input'>";

But this doesn't: (It just creates an empty file)

file_put_contents($output, file_get_contents($input));

and throws a no such file or directory exception, tho its the same url as the one used for the src property showing the image.

What is the problem trying to save it like that?

Im not sure whether the problem is the file_put_contents or the file_get_contents

al'ein
  • 1,711
  • 1
  • 14
  • 21
Minzkraut
  • 2,149
  • 25
  • 31

3 Answers3

1

You can use file_get_contents() to load a file from the filesystem or from a remote host over HTTP. But you need to give PHP the full url in order to make use of the HTTP functionality (the php.ini also needs to allow this). Otherwise it literally searchs for the file create_image/identicon.php?size=48&hash=$hashvalue (variables of course replaced) on the filesystem.

Charlotte Dunois
  • 4,638
  • 2
  • 20
  • 39
0

try this imagepng($input, $output); instead of file_put_contents

Zakaria
  • 170
  • 1
  • 9
  • how do i input it correctly? when i insert $input as i have it now, i throws an error (expects param,eter 1 to be resource)... i read the manual page for imagepng but no matter what i try it wont work – Minzkraut Aug 31 '15 at 12:00
0

file_x_contents works with real paths, and your img src works with the webpath. So file_get_contents needs the UNIX-Path. EDIT: As it was pointed out in the comments it is possible to work with URL's if enabled in the php.ini

Doktor OSwaldo
  • 5,732
  • 20
  • 41