❶ php里怎么把网上的图片保存在本地
火车头采集,采集侠。自己写也可以,写正则抓图片地址,然后用file_get_contents函数读取内容,写文件。
❷ 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>";
returntrue;
}
$databasename="database";//数据库名称
do
{
$con=mysql_select_db($databasename,$conn);
}while(!$con);
if($con==FALSE)
{
echo"<center>打开数据库失败!<br>请刷新后重试。</center>";
returntrue;
}
?>
2.upload.php
<?php
if($_GET['action']=="save"){
include_once('conn.php');
include_once('uploadclass.php');
$title=$_POST['title'];
$pic=$uploadfile;
if($title=="")
echo"<Script>window.alert('对不起!你输入的信息不完整!');history.back()</Script>";
$sql="insertintoupload(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>
<formmethod="post"action="?action=save"enctype="multipart/form-data">
<tableborder=0cellspacing=0cellpadding=0align=centerwidth="100%">
<tr>
<tdwidth=55height=20align="center"></TD>
<tdheight="16">
<tablewidth="48%"height="93"border="0"cellpadding="0"cellspacing="0">
<tr>
<td>标题:</td>
<td><inputname="title"type="text"id="title"></td>
</tr>
<tr>
<td>文件:</td>
<td><label>
<inputname="file"type="file"value="浏览">
<inputtype="hidden"name="MAX_FILE_SIZE"value="2000000">
</label></td>
</tr>
<tr>
<td></td>
<td><inputtype="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/";//程序所在路径
//获取文件后缀名函数
functionfileext($filename)
{
returnsubstr(strrchr($filename,'.'),1);
}
//生成随机文件名函数
functionrandom($length)
{
$hash='CR-';
$chars='';
$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";
$uploadfile=$uploaddir.$name;
}
while(file_exists($uploadfile));
if(move_uploaded_file($_FILES['file']['tmp_name'],$uploadfile))
{
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
echo"上传失败!";
}
else
{//输出图片预览
echo"<center>您的文件已经上传完毕上传图片预览:</center><br><center><imgsrc='$uploadfile'></center>";
echo"<br><center><ahref='upload.htm'>继续上传</a></center>";
}
}
}
?>
❸ PHP 保存文章远程图片到本地
$reg = "/<img[^>]*src=\"(http:\/\/(.+)\/(.+)\.(jpg|gif|bmp|bnp))\"/isU";
preg_match_all($reg, $message, $img_array, PREG_PATTERN_ORDER);
$img_array = array_unique($img_array[1]);
foreach ($img_array as $img){你的代码...}
❹ php 接收并保存图片
获取远程图片并把它保存到本地确定您有把文件写入本地服务器的权限变量说明: $url 是远程图片的完整URL地址,不能为空。
$filename 是可选变量:
如果为空,
本地文件名将基于时间和日期 自动生成.
❺ php保存远程图片到本地
$img = file_get_contents('http://www.91cici.com/images/logo.gif');
file_put_contents('test.gif',$img);
❻ 用php如何把图像数据流保存
imagegif(resource $image [, string $filename ]) 从 image 图像以 filename 为文件名创建一个 GIF 图像。image 参数是 imagecreate() 或 imagecreatefrom* 函数的返回值。
imagejpeg(resource $image [, string $filename ]) 从 image 图像以 filename 为文件名创建一个 JPEG 图像。
imagepng(resource $image [, string $filename ]) 将 GD 图像流(image)以 PNG 格式输出到标准输出(通常为浏览器),或者如果用 filename 给出了文件名则将其输出到该文件。
filename 文件保存的路径,如果未设置或为 NULL,将会直接输出原始图象流。
这几个函数你参考一下,希望对你有帮助。
❼ PHP 怎么保存原图片
file_get_contents()抓取下来,再file_put_contents()写入本地
❽ php保存图片只能保存图片不能保存路径
据我的了解……步骤如下:
web服务器接受到你上传的图片或文件,就会扔到一个临时文件夹中
你可以用$_FILES['myfile']['tmp_name']获取你刚刚上传的文件
然后,你再用move_uploaded_file,将你上传的文件移到指定的目录中,就有了你想要的保存路径了……
具体代码如下:网上的,我没有测试
<?php
//1.接收提交文件的用户
$username=$_POST['username'];
$fileintro=$_POST['fileintro'];
//我们这里需要使用到$_FILES
/*echo"<pre>";
print_r($_FILES);
echo"</pre>";*/
//其实我们在上传文件时,点击上传后,数据由http协议先发送到apache服务器那边,这里apache服务器已经将上传的文件存放到了服务器下的C:windowsTemp目录下了。这时我们只需转存到我们需要存放的目录即可。
//php中自身对上传的文件大小存在限制默认为2M
//获取文件的大小
$file_size=$_FILES['myfile']['size'];
if($file_size>2*1024*1024){
echo"文件过大,不能上传大于2M的文件";
exit();
}
$file_type=$_FILES['myfile']['type'];
echo$file_type;
if($file_type!="image/jpeg"&&$file_type!='image/pjpeg'){
echo"文件类型只能为jpg格式";
exit();
}
//判断是否上传成功(是否使用post方式上传)
if(is_uploaded_file($_FILES['myfile']['tmp_name'])){
//把文件转存到你希望的目录(不要使用函数)
$uploaded_file=$_FILES['myfile']['tmp_name'];
//我们给每个用户动态的创建一个文件夹
$user_path=$_SERVER['DOCUMENT_ROOT']."/studyphp/file/up/".$username;
//判断该用户文件夹是否已经有这个文件夹
if(!file_exists($user_path)){
mkdir($user_path);
}
//$move_to_file=$user_path."/".$_FILES['myfile']['name'];
$file_true_name=$_FILES['myfile']['name'];
$move_to_file=$user_path."/".time().rand(1,1000).substr($file_true_name,strrpos($file_true_name,"."));
//echo"$uploaded_file$move_to_file";
if(move_uploaded_file($uploaded_file,iconv("utf-8","gb2312",$move_to_file))){
echo$_FILES['myfile']['name']."上传成功";
}else{
echo"上传失败";
}
}else{
echo"上传失败";
}
?>
❾ PHP 怎么把网络图片存到本地
右击鼠标,图片另存为,ok了
❿ php 怎么从网上下载图片到本地
我想告诉你,除了显示网址,然后“另存为”或者用迅雷之类的下载外,php真的还无法下载到本地,好像是因为权限什么的。
我琢磨了好久都不可能下载到本地,除非你的服务器是建立在本地的。
我自己写了一个函数,用来拷贝图片的,用()不行。
你可以看看,其他文件格式同理。
//----------------------拷贝图片(包括网络图片)到指定网址------------------
//-------适用于图片类型包括:jpeg、gif、png-----------
function down_image($url1,$url2){//---$url1为源网址,$url2为目标网址---
$url1_info=pathinfo($url1);
$url2_info=pathinfo($url2);
$msg="拷贝成功!";
if($url1_info[extension]==$url2_info[extension]){
switch ($url1_info[extension]){
case "jpg":
$img=imagecreatefromjpeg($url1);
imagejpeg($img, $url2);
break;
case "gif":
$img=imagecreatefromgif($url1);
imagegif($img, $url2);
break;
case "png":
$img=imagecreatefrompng($url1);
imagepng($img, $url2);
break;
}
}else{
$msg="文件类型不正确,拷贝失败";
}
return $msg;
}