很多站长朋友们都不太清楚php解析成图片,今天小编就来给大家整理php解析成图片,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 初学php生成图像,输出到浏览器中,看不了图片,是什么问题 2、 用php的gd库生成png图片,用浏览器不能执行成功 3、 PHP怎么把图片数据保存为jpg图片到服务器目录 4、 我用PHP代码生成一张图片,但显示不出来 初学php生成图像,输出到浏览器中,看不了图片,是什么问题<?php
header("content-type:image/png");
$im = @imagecreatetruecolor(120, 20) or die('Cannot Initialize new GD image stream');
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color);
imagepng($im);
imagedestroy($im);
?>
你这个是要输出图片,因此只需要这部分就可以了。你的出现乱码是因为你header之前输出了<html><head>等等东西导致header失败。
用php的gd库生成png图片,用浏览器不能执行成功你这个代码我在window上用过了,可以生成图片,代码没问题。
问题很有可能在apache上。你可以写一个crontab测试apache是否正常,如果不正常可以:
1,是否有脚本死循环
2, php.ini里memory_limit大小给的是否合适
3, httpd.conf里,合理调整 ServerLimit MaxClients 和 MaxRequestsPerChild
找不到的话可以直接在百度搜索里面搜这个child pid 2578 exit signal Segmentation fault (11)参考一下
PHP怎么把图片数据保存为jpg图片到服务器目录第一步:通过$_FILES获取文件信息。
第二步:指定新文件名称以及路径,并赋值给一个变量。
第三步:通过move_uploaded_file上传文件。
第四步:上传成功后,将数值存入数据库服务器目录即可。
代码如下
1.conn.php
<?
$host="localhost"; //数据库服务器名称
$user="root"; //用户名
$pwd="1721"; //密码
$conn=mysql_connect($host,$user,$pwd);
mysql_query("SET
character_set_connection=gb2312,
character_set_results=gb2312,
character_set_client=binary",$conn);
if ($conn==FALSE)
{
echo "<center>服务器连接失败!<br>请刷新后重试。</center>";
return true;
}
$databasename="database";//数据库名称
do
{
$con=mysql_select_db($databasename,$conn);
}while(!$con);
if ($con==FALSE)
{
echo "<center>打开数据库失败!<br>请刷新后重试。</center>";
return true;
}
?>
2.upload.php
<?php
if ($_GET['action'] == "save"){
include_once('conn.php');
include_once('uploadclass.php');
$title=$_POST['title'];
$pic=/data/upload/help/202303/13/c96ee63fd4b3b03bcf6254e335084757.;
if($title == "")
echo"<Script>window.alert('对不起!你输入的信息不完整!');history.back()</Script>";
$sql="insert into upload(title,pic) values('$title','$pic')";
$result=mysql_query($sql,$conn);
//echo"<Script>window.alert('信息添加成功');location.href='upload.php'</Script>";
}
?>
<html>
<head>
<title>文件上传实例</title>
</head>
<body>
<form method="post" action="?action=save" enctype="multipart/form-data">
<table border=0 cellspacing=0 cellpadding=0 align=center width="100%">
<tr>
<td width=55 height=20 align="center"> </TD>
<td height="16">
<table width="48%" height="93" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>标题:</td>
<td><input name="title" type="text" id="title"></td>
</tr>
<tr>
<td>文件: </td>
<td><label>
<input name="file" type="file" value="浏览" >
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
</label></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="上 传" name="upload"></td>
</tr>
</table></td>
</tr>
</table>
</form>
</body>
</html>
3.uploadclass.php
<?php
$uploaddir = "/upfiles/";//设置文件保存目录 注意包含/
$type=array("jpg","gif","bmp","jpeg","png");//设置允许上传文件的类型
$patch="upload/";//程序所在路径
//获取文件后缀名函数
function fileext($filename)
{
return substr(strrchr($filename, '.'), 1);
}
//生成随机文件名函数
function random($length)
{
$hash = 'CR-';
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
$max = strlen($chars) - 1;
mt_srand((double)microtime() * 1000000);
for($i = 0; $i < $length; $i++)
{
$hash .= $chars[mt_rand(0, $max)];
}
return $hash;
}
$a=strtolower(fileext($_FILES['file']['name']));
//判断文件类型
if(!in_array(strtolower(fileext($_FILES['file']['name'])),$type))
{
$text=implode(",",$type);
echo "您只能上传以下类型文件: ",$text,"<br>";
}
//生成目标文件的文件名
else{
$filename=explode(".",$_FILES['file']['name']);
do
{
$filename[0]=random(10); //设置随机数长度
$name=implode(".",$filename);
//$name1=$name.".Mcncc";
/data/upload/help/202303/13/c96ee63fd4b3b03bcf6254e335084757.=$uploaddir.$name;
}
while(file_exists(/data/upload/help/202303/13/c96ee63fd4b3b03bcf6254e335084757.));
if (move_uploaded_file($_FILES['file']['tmp_name'],/data/upload/help/202303/13/c96ee63fd4b3b03bcf6254e335084757.))
{
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
echo "上传失败!";
}
else
{//输出图片预览
echo "<center>您的文件已经上传完毕 上传图片预览: </center><br><center><img src='/data/upload/help/202303/13/c96ee63fd4b3b03bcf6254e335084757.'></center>";
echo "<br><center><a href='upload.htm'>继续上传</a></center>";
}
}
}
?>
我用PHP代码生成一张图片,但显示不出来$_nmsg='';//在for循环前面加上 你没定义就.= 会出警告的
或者 在header前面加 ob_clean();
生成验证码最好都clean一下
关于php解析成图片的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。
查看更多关于php解析成图片 php解析js的详细内容...