当前位置:首页 » 文件管理 » php异步上传图片

php异步上传图片

发布时间: 2025-10-19 06:01:23

phpcms v9后台上传图片时出现缺少图像源文件地址

解决步骤如下:
1.在安装PHP环境的目录下面,找到 php.ini文件。
2. 打开php.ini ,查找upload_tmp_dir ,把这个词前面的“;”号去掉,使其生效,然后在“=”号后面加上临时文件夹的目录,比如: c:/windows/temp,这个可以自设。
3.在这个文件夹的安全属性里添加 "everyone"用户,赋予读写权限。

㈡ 一php网站,从前空间搬家以后,FCKeditor的上传图片功能不好用了,提示上传正确但是没有文件,求解决方法

FCKeditor的上传图片功能不好用了??

是不是有时候上传上去,有时候传不上去? 如果是这样,问题应该是图片大小上,可能新换的这个空间允许上传的图片太小。

如果每次都传不上去,考虑以下几点:
1、空间是否有足够的容量
2、上传目录是否存在,或 写的权限
3、程序中是否限止了上传文件类型

用的是IIS,站点设置中开启了支持”父级目录“ 应该就行了

㈢ php上传图片并压缩-thinkphp如何做图片压缩呢

php压缩图片

比如(什么?)上面有不同大小的图片--------语文表达缺主语,含糊导致无法理解。

服务器上面?客户机上面?具体什么软件环境上面?

“有不同大小的图片”,已经存在的图片通常已经压缩过的,像JPEG更是有损压缩。再次压缩必定再次会降低画质。PHP可以再次处理图片,但画质和存储大小不能兼得,画质好就存储大,要存储小就画质差,根据自己的画质需求处理。

thinkphp如何做图片压缩呢?

在上传图片的时候先看看图片有多大,一般来说导航幻灯片的图片单张大小尽量不超100k,产品图不超过20k,这样加载还慢的话就用ajax后加载方法,可以是滚动加载之类,但是对蜘蛛抓取页面并不是很友好。

至于你说的用tp把图片压缩,那只能是将图片的尺寸改成你想要的尺寸,大小的话是web所用格式大小,等页面加载完你又换原图,这样相当于又加载了一遍,还不如做ajax滚动加载。

PHP网站上传图片自动压缩,怎么编程啊,求指

这里会使用到三个文件:

:连接数据库

test_:执行sql语句

upload_:上传图片并压缩

三个文件代码如下:

连接数据库:

<?php

$db_host=''

$db_user=''

$db_psw=''

$db_name=''

$db_port=''

$sqlconn=new_ysqli($db_host,$db_user,$db_psw,$db_name);

$q="set_ames_tf8;";

$result=$sqlconn->query($q);

if(mysqli_connect_errno())_

_rintf("Connect_ailed:%s ",_ysqli_connect_error());

_xit();

}

?>

当然使用一些封装的数据库类也是可以的。

执行SQL语句:test_

<?php

require("");

require("upload_");

$real_img=$uploadfile;

$small_img=$uploadfile_resize;

$insert_sql="insert_nto_mg(real_img,small_img)_alues(?,?)";

$result=$sqlconn->_repare($insert_sql);

$result->_ind_param("ss",$real_img,$small_img);

$result->_xecute();

?>

上传图片并压缩:upload_

<?php

//设置文件保存目录

$uploaddir="upfiles/";

//设置允许上传文件的类型

$type=array("jpg","gif","bmp","jpeg","png");

//获取文件后缀名函数

function_ileext($filename)

{

_eturn_ubstr(strrchr($filename,'.'),1);

}

//生成随机文件名函数

function_andom($length)

{

$hash='CR-'

$chars=''

$max=_trlen($chars)-1;

_t_srand((double)microtime()*1000000);

_or($i=0;$i<$length;$i++)

_

_$hash.=$chars[mt_rand(0,$max)];

_

_eturn$hash;

}

$a=strtolower(fileext($_FILES['filename']['name']));

//判断文件类型

if(!in_array(strtolower(fileext($_FILES['filename']['name'])),$type))

{

$text=implode(",",$type);

$ret_code=3;//文件类型错误

$page_result=$text;

$retArray=_rray('ret_code'=>$ret_code,'page_result'=>$page_result);

$retJson=_son_encode($retArray);

_cho$retJson;

_eturn;

}

//生成目标文件的文件名

else

{

$filename=explode(".",$_FILES['filename']['name']);

_o

_

_$filename[0]=random(10);//设置随机数长度

_$name=implode(".",$filename);

_//$name1=$name.".Mcncc";

_$uploadfile=$uploaddir.$name;

_

_hile(file_exists($uploadfile));

_f(move_uploaded_file($_FILES['filename']['tmp_name'],$uploadfile))

_

_if(is_uploaded_file($_FILES['filename']['tmp_name']))

_{

_$ret_code=1;//上传失败

_}

_lse

_//上传成功

_$ret_code=0;

_

_

$retArray=_rray('ret_code'=>$ret_code);

$retJson=_son_encode($retArray);

echo$retJson;

}

//压缩图片

$uploaddir_resize="upfiles_resize/";

$uploadfile_resize=$uploaddir_resize.$name;

//$pic_width_max=120;

//$pic_height_max=90;

//以上与下面段注释可以联合使用,可以使图片根据计算出来的比例压缩

$file_type=$_FILES["filename"]['type'];

function_esizeImage($uploadfile,$maxwidth,$maxheight,$name)

{

//取得当前图片大小

$width=_magesx($uploadfile);

$height=_magesy($uploadfile);

$i=0.5;

//生成缩略图的大小

_f(($width>$maxwidth)_|($height>$maxheight))

_

_/*

_$widthratio=$maxwidth/$width;

_$heightratio=$maxheight/$height;

_

_if($widthratio<$heightratio)

_{

_$ratio=$widthratio;

_}

_else

_{

__$ratio=$heightratio;

_}

_

_$newwidth=$width*$ratio;

_$newheight=$height*$ratio;

_*/

_$newwidth=$width*$i;

_$newheight=$height*$i;

_if(function_exists("imageresampled"))

_{

_$uploaddir_resize=_magecreatetruecolor($newwidth,$newheight);

__mageresampled($uploaddir_resize,$uploadfile,0,0,0,0,$newwidth,$newheight,$width,$height);

_}

_else

_{

_$uploaddir_resize=_magecreate($newwidth,$newheight);

__mageresized($uploaddir_resize,$uploadfile,0,0,0,0,$newwidth,$newheight,$width,$height);

_}

_

_ImageJpeg($uploaddir_resize,$name);

_ImageDestroy($uploaddir_resize);

_

_lse

_

_ImageJpeg($uploadfile,$name);

_

}

if($_FILES["filename"]['size'])

{

_f($file_type=="image/pjpeg"||$file_type=="image/jpg"|$file_type=="image/jpeg")

_

_//$im=_magecreatefromjpeg($_FILES[$upload_input_name]['tmp_name']);

_$im=_magecreatefromjpeg($uploadfile);

_

_lseif($file_type=="image/x-png")

_

_//$im=_magecreatefrompng($_FILES[$upload_input_name]['tmp_name']);

_$im=_magecreatefromjpeg($uploadfile);

_

_lseif($file_type=="image/gif")

_

_//$im=_magecreatefromgif($_FILES[$upload_input_name]['tmp_name']);

_$im=_magecreatefromjpeg($uploadfile);

_

_lse//默认jpg

_

_$im=_magecreatefromjpeg($uploadfile);

_

_f($im)

_

_ResizeImage($im,$pic_width_max,$pic_height_max,$uploadfile_resize);

_

_ImageDestroy($im);

_

}

?>

请按照现实情况更改,test_中对应的信息。

望采纳,谢谢。

㈣ 异步上传图片,怎么实现表单提交,不刷新页面,并且回显图片

你这是要用AJAX啊。
用JQUERY会方便一点。如果要用原生的js.
var xmlHttp=new XMLHttpRequest();
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
然后你的xmlHttp.open("POST",url);这里必须用POST。
接下来,就是xmlHttp.send(你的数据文件)
我这里是简写了。xmlHttp的生成在IE和其实浏览器下实例化是不一样的。你可以找一下资料。

接下来,就是提交到服务器上去了,你的程序处理保存图片后,生成一个地址后回传给请求的页面。
你再xmlHttp.responseText获取这个地址,就可以回显了。

热点内容
小型机算法 发布:2025-10-19 08:16:39 浏览:174
如何用c编程 发布:2025-10-19 08:16:03 浏览:22
linux使用情况 发布:2025-10-19 07:57:38 浏览:46
c编程视频教学 发布:2025-10-19 07:41:13 浏览:326
mac系统怎么解压缩 发布:2025-10-19 07:17:15 浏览:345
数据库操作类型 发布:2025-10-19 07:13:31 浏览:253
php函数合并 发布:2025-10-19 07:00:33 浏览:928
算法循环 发布:2025-10-19 06:40:34 浏览:930
squid代理ftp 发布:2025-10-19 06:25:53 浏览:212
php定义全局变量 发布:2025-10-19 06:21:49 浏览:38