some1
some1

Reputation: 1747

How to save an image generated by a php script?

I have a 3rd party php file that generates barcodes, called barcode.php.

When I want to generate a new barcode, I call that script, like this:

<img alt="testing" src="barcode.php?text=455555442233&codetype=Code25" />

Is there an easy way to save the image that is generated onto the server, without modifying the barcode.php script?

Upvotes: 2

Views: 1516

Answers (1)

user557846
user557846

Reputation:

$file = 'barcode.jpg'; //file name to write to include location if needed
$current = file_get_contents('http://yoursite.com/barcode.php?text=455555442233&codetype=Code25');//read the created file
file_put_contents($file, $current);//write it

using the external url here may be sub-optimal depending on circumstances

Upvotes: 1

Related Questions