當前位置:首頁 » 文件管理 » 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獲取這個地址,就可以回顯了。

熱點內容
linux使用情況 發布:2025-10-19 07:57:38 瀏覽:45
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
為什麼要做配置中心 發布:2025-10-19 06:18:11 瀏覽:82
php非同步上傳圖片 發布:2025-10-19 06:01:23 瀏覽:526