Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将条形码图像保存到计算机驱动器中的文件夹?_Php - Fatal编程技术网

Php 如何将条形码图像保存到计算机驱动器中的文件夹?

Php 如何将条形码图像保存到计算机驱动器中的文件夹?,php,Php,我已经使用PHP条形码插件创建了一个条形码 HTML 如何将此条形码图像保存到本地硬盘?尝试此操作获取内容并将其保存到文件 $barcode = file_get_contents('http://www.youdomain.com/barcode.php?codetype=Code128&size=50&text=123421321321321321'); //you can also use below function get more info on image

我已经使用PHP条形码插件创建了一个条形码

HTML



如何将此条形码图像保存到本地硬盘?

尝试此操作获取内容并将其保存到文件

$barcode = file_get_contents('http://www.youdomain.com/barcode.php?codetype=Code128&size=50&text=123421321321321321');

//you can also use below function get more info on image 
//$imgInfo = getimagesize($barcode);

//save the file to disk 
file_put_contents('path_to_file/code.png', $barcode);
使用卷曲

//You can also try it using CURL if above doesn't works

$ch = curl_init('http://www.youdomain.com/barcode.php?codetype=Code128&size=50&text=123421321321321321');
$fp = fopen('path_to_file/code.png', 'wb');
      curl_setopt($ch, CURLOPT_FILE, $fp);
      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_exec($ch);
      curl_close($ch);
fclose($fp);
编辑条形码.php

现在它非常简单,就像在文件中,它只是返回图像的头一样,就在您可以添加这一行以将其保存到服务器之前

// Save the image to file.png
imagepng($image, "file.png"); // Your barcode will be saved here with name file.png

// Draw barcode to the screen
header ('Content-type: image/png');
imagepng($image);
imagedestroy($image);

希望这有帮助

请发布您的
条形码
创建代码,以便更好地理解。右键单击->保存到磁盘?你在问什么?您在
barcode.php
中实际查看了什么?呃……对不起,我是说如何在页面加载时自动保存条形码图像。感谢上帝,网站无法直接将内容写入用户的本地磁盘!deceze,我的意思是在服务器中写入我的目的是想将图像自动保存到磁盘,不需要警报消息保存框。警告:文件获取内容(barcode.php?codetype=Code128&size=50&text=123421321)[function.file get contents]:无法打开流:第12行barcode.php的D:\wamp\www\SVN\roadTax\doc.php中没有这样的文件或目录不正确,尝试绝对路径,它应该会工作。我确信barcode.php的路径是正确的,因为它位于同一根目录中。使用barcode.php的绝对url,如下所示
file\u get\u contents('http://www.youdomain.com/barcode.php?codetype=Code128&size=50&text=123421321321321321');我仍然收到此错误警告:file\u put\u contents()[function.file put contents]:无法打开流:HTTP包装器不支持第34行的D:\wamp\www\SVN\roadTax\doc.php中的可写连接。
// Save the image to file.png
imagepng($image, "file.png"); // Your barcode will be saved here with name file.png

// Draw barcode to the screen
header ('Content-type: image/png');
imagepng($image);
imagedestroy($image);