ÎļþÉÏ´«ÏÖÔÚ¶¼ÊǺܳ£¼uµÄÁË£¬¿ÉÒÔÉÏ´«Îļþ£¬ÉÏ´«Í*ÏñµÈ£¬²»Í¬µÄa¯ÀÀÆ÷¡°ÎļþÉÏ´«¡±Óв»Í¬µÄЧ¹u
ÏÈ¿´Ï»ðºua¯ÀÀÆ÷µÄЧ¹uÊÇÕaÑuµÄ£º
ÔÙ¿´ÏÂIEa¯ÀÀÆ÷ÊÇÕaÑuµÄ£º
»¹ÓкܶaÆaËuµÄa¯ÀÀÆ÷£¬¾Í²»Ò»Ò»µÄ²e¿´Ð§¹uÁË£¬ÄÇôÕa¸oÉÏ´«ÊÇÔoôʵÏÖµÄÄØ£¿
Ò»¡¢ÎļþÉÏ´«¹¦ÄÜ
£¨1£(C)µÚÒ»ÊÇÒªÓÐÕa¸oÉÏ´«Ò³ÃaeÁË
Ê×ÏÈÊÇҪд±iµ¥ÔªËØÁË£¨ÆaÖоÍÓд¦ÀiÒ³Ãae¡°¹ØÓÚÉÏ´«µÄ´¦ÀiÁË£¬ÆaÖÐÓÐÐ(C)¹aeÔo¿ÉÒÔд¡±£¬»¹Óд«Êa*½Ê½£¬ÔÙ¾ÍÊÇÒ»¸oÖØÒªµÄÊoÐÔ£¬ÒoΪÊÇÎļþÉÏ´«£¬ËuÒÔÒªÓÐÕa¸oÊoÐÔ£ºenctype="multipart/form-data"£(C)ÔÙ¾ÍÊǹØÓÚ°´Å¥ÁË£¬±iµ¥¾o¶¨Ö®ºo£¬¾ÍÊÇÀiÃaeµÄÄÚÈÝ£¬ÎļþÉÏ´«×ÔÈ»°´Å¥µÄÀaÐÍÊÇ¡°file¡±£»È»ºo¾ÍÊÇ¡°ÉÏ´«¡±°´Å¥ÁË£¬Õa¸oÒªÓõ½Ìa½»£¬ËuÒÔ°´Å¥ÀaÐÍÒªÓá°submit¡±µÄ£¬´uÂeÈçÏ£º
<form action="wenjiansccl.php" method="post" enctype="multipart/form-data"> <!--´¦ÀiÒ³ÃaeÆð¸oÃu×Ö£¬×oÎļþÉÏ´«ÊÇÕa¸oÊoÐÔ£ºenctype="multipart/form-data"-->
¡¡¡¡<input type="file" name="file"/> //a¯ÀÀÎļþµÄ°´Å¥
¡¡¡¡<input type="submit" value="ÉÏ´«" /> //Ìa½»µÄÉÏ´«°´Å¥
</form>
ÏÈ¿´ÏÂЧ¹u£º
¡¡¡¡
£¨2£(C)µÚ¶þ¾ÍÊÇÖØÒªµÄÎļþÉÏ´«µÄ´¦ÀiÒ³ÃaeÁË
ÎÒÃÇ¿ÉÒÔÏÈÉÏ´«ÖµÊa³oÏ£¬¿´ÏÂÎļþÉÏ´«Ö®ºo»a³oÏÖʲô¶«Î÷£¬×¢ÒaµÄÊÇ£ºÎļþµÄ´«Öµ½Ê½£¬ÕaÀi²»ÄÜÓÃpost»oÊÇgetÁË£¬ÒªÓÃ$_FILES[""]Õa¸o´«Öµ½Ê½
var_dump($_FILES["file"]); //Êa³o´«¹ýÀ´µÄÖµ
Êa³o½a¹uÈçͼ£º
×¢Òa£ºÒoΪÏÂÃae»aÓõ½ÕaÕÅͼÖеÄÐÅÏ¢£¬ÔÚÕa¸oÎÒÏÈÆð¸oÃu×Ö£¨array£(C)£¬±aÓÚÏÂÃaeÓõ½Ê±½²Êo²»Ça³þ
²»ÄÑ¿´³oÊý¸o¶þάÊý×e£ºÆaÖÐÓÐÎļþµÄÃu³Æ£¬ÀaÐÍ£¬±£´aeλÖ㬴iÎoÐÅÏ¢ºÍÎļþµÄ´oС£¬ÕaÑuÆaʵÎļþ¾Í»aÁÙʱµÄ±£´aeÔÚ*þÎñÆ÷ÉÏÁË
ÉÏ´«ÎļþʱÓÐ4Ïi×¢ÒaÏi£º
1.¿ØÖÆÉÏ´«ÎļþµÄÀaÐÍ
2.¿ØÖÆÉÏ´«ÎļþµÄ´oС
3.*ÀÖ¹ÎļþÃuÖظ´
¡¡¡¡3.1Ð޸ı£´aeµÄÎļþÃu
¡¡¡¡ 3.11Óû§Ãu+ʱ¼a´Á+Ëae»uÊý+ÎļþÃu
¡¡¡¡3.12Á÷Ë®ºÅ
¡¡¡¡3.2ʹÓÃÎļþ¼Ð
¡¡¡¡ 3.21public/lch/2017-2-12/1.jpg
4.±£´aeÎļþ
ÖªµÀÁËÕaËÄÏi×¢ÒaÏi£¨Ò²Ïaµ±ÓÚ²½Öe£(C)£¬ÄÇô¾Í¿ªÊ¼Ò»²½Ò»²½µÄд´¦ÀiÒ³Ãae¾Í¿ÉÒÔÁË
£¨1£(C)ÔÚÊa³oʱ£¬¿ÉÒÔ¿´µ½²»ÊÇÓÐÒ»ÏiÊÇ¡°´iÎo¡±ÏiÂi£¬Ê×ÏÈ¿ÉÒÔÅжÏÏÂÊÇ*ñ´«ÊaÓÐÎo
if($_FILES["file"]["error"]) //½«Îļþ´«Öµµ½´¦ÀiÒ³Ãae£¬ÕÒµ½³o´iµÄË÷Òý£¬Ò²¾ÍÊÇ£¨array£(C)ͼÖеĴiÎoÏierror
{
echo $_FILES["file"]["error"];
}
£¨2£(C)ÉÏÃaeÊÇÈç¹u³o´i¾ÍÊa³o³o´iÐÅÏ¢£¬Ã»Óдi¾ÍÊǽøÐÐÏÂÃaeµÄÄÚÈÝÁË£º°´ÕÕ×¢ÒaÊÂÏi¿ªÊ¼Ð´°É
Ê×ÏÈÊÇ£º¿ØÖÆÎļþÉÏ´«Ê±µÄÀaÐͺʹoС£¨Ò²ÊÇ´Ó£¨array£(C)ͼÖÐÕÒµ½ÀaÐÍtypeºÍ´oСsize£¬È»ºo½«ËuÃǸ³ÏeÒªµÄÀaÐÍÖµ¾Í¿ÉÒÔÁË£(C)ÎÒÃÇÏÞ¶¨ÁËjpegºÍpngÕaÁ½ÖÖ£¬Ò²¿ÉÊǶaÖÖ£¬Óá°»o¡±Ð´ÉϾͿÉÒÔÁË¡£ÕaÀiÒ²ÓøoifÓi¾aÅжÏÏ£¨Èç¹uÎļþÀaÐÍÊÇjpeg»oÊÇpng²¢ÇÒÎļþ´oСÊÇСÓÚ1024000µÄ¾Í¿ÉÒÔÉÏ´«£¬*ñÔo¾ÍÊÇÉÏ´«Ê§°Ü£(C)
if($_FILES["file"]["type"]=="image/jpeg" || $_FILES["file"]["type"]=="image/png" && $_FILES["file"]["size"]<1024000)
{<br>¡¡¡¡//×¢ÒaÊÂÏi3ºÍ4µÄÄÚÈÝ<br>}
else
{
¡¡¡¡echo "ÎļþÀaÐͲ»ÕýÈ*£¡";
}
£¨3£(C)ÔÚ´uÂeÖеÄ×¢ÊÍ£¨×¢ÒaÊÂÏi3ºÍ4µÄÄÚÈÝ£(C)´¦¿ªÊ¼Ð´ÎļþµÄ±ÜÃaÖظ´ºÍ±£´ae
µÚÒ»£ºÕÒµ½ÎļþµÄ±£´aeλÖã¨ÏeÒª±£´aeÔÚÄĸoλÖã(C)£¬È»ºoÆ´½ÓÉÏÐÞ¸ÄÎļþÃuµÄ½Ê½£¨Ê¹ÓÃʱ¼a´Á½Ê½£(C)
$filesname = "./files/".date("YmdHis").$_FILES["file"]["name"]; //$_FILES["file"]["name"]ÕaҲͬÑuµÄÒ²ÊÇ£¨array£(C)ͼµÄÃu³Æname
µÚ¶þ£ºÅжÏÎļþÊÇ*ñ´aeÔÚ£¨´aeÔÚ¾ÍÌaʾ£¬²»´aeÔھͱ£´aeµ½Îļþ¼ÐÖУ(C)
if(file_exists($filesname)) //file_exists()*½*¨£ºÅжÏÎļþÊÇ*ñ´aeÔÚ£¬ÀiÃaeµÄÖµ¾ÍÊǶ¨ÒaµÄ±£´aeλÖÃ
{
¡¡¡¡echo "ÎļþÒѾ´aeÔÚ"; //´aeÔÚ¸ø³oÌaʾ
}
else
{
¡¡¡¡//²»´aeÔھͣ¬±£´aeÎļþ£¨move_uploaded_file()±£´ae£(C)
¡¡¡¡move_uploaded_file($_FILES["file"]["tmp_name"],$filesname); //ÀiÃaeµÄÖµÒªÓе±Ç°µÄ±£´aeλÖ㬽«Òª±£´aeµ½ÄĵÄλÖÃ
}
<span style="font-family: ËÎÌa; font-size: 15px"><span style="font-size: 18px">×¢Òa£º</span><br>1.¿ÉÄÜÉÏ´«µÄʱºoÊÇUTF-8µÄ±aÂe¸ñʽ£¬WindowsÊÇÓõĹu±eµÄ±aÂe¸ñʽ£¬ÉÏ´«ÉϺº×Ó¿ÉÄܳÉΪÂÒÂeÁË£¬¿ÉÒÔÔÚÎļþ±£´aeλÖÃÏÂÃae¼ÓÉÏ¡°×ª»»±aÂe¸ñʽ¡±<br>ʹÓõÄÊÇ£º</span><span style="font-size: 15px">iconv()*½*¨£º</span><span style="font-size: 15px">ÀiÃaeÓÐ3¸oÖµ£¬Ò»ÊÇÏÖÔÚʹÓõıaÂe¸ñʽ£¬¶þÊÇÏeҪת»»µÄ±aÂe¸ñʽ£¬ÈýÊÇÏeҪת»»µÄ×Ö*u´®</span>
$filename = iconv("UTF-8","gb2312",$filesname); //Õa¸oiconv()ÀiÃaeÓÐ3¸oÖµ£¬Ò»ÊÇÏÖÔÚʹÓõıaÂe¸ñʽ£¬¶þÊÇÏeҪת»»µÄ±aÂe¸ñʽ£¬ÈýÊÇÏeҪת»¯µÄ×Ö*u´®
<span style="font-family: ËÎÌa; font-size: 15px">2.Èç¹uÉÏÃaeµÄÎļþµÄÉÏ´«¸ñʽÊǴ۸ĵĸñʽ£¬Ò²ÓÃmove_uploaded_file()*½*¨</span>
µ½´ËÕa¸oÎļþÉÏ´«¾Í½aÊøÁË£¬¿ÉÒÔÊÔһϡ£
¶þ£¬ÉÏ´«ÎļþÔ¤ÀÀ
ÉÏ´«Í¼Æ¬Ê±£¬¶¼»aÏÈ¿´Ð§¹uÔoôÑu£¬È»ºoÔÙÉÏ´«µÄ£¬½ÓÏÂÀ´¾ÍÊÇͼƬԤÀÀ¹¦ÄÜÁË
£¨1£(C)¿ÉÒÔÏÈÓиoÎļþ°´Å¥£¬ÓÃÓÚÑ¡ÔñÎļþ
<input id="uploadImage" type="file" name="photoimage" class="fimg1" onchange="PreviewImage();" /> //¶ÔÕa¸o°´Å¥¼ÓÒ»¸oʼþ
£¨2£(C)ÓÃÓÚÏÔʾµÄÕa¸oͼƬµÄÒ»¸odiv
<div id="uploadPreview"></div>
¸øÕa¸odiv¼ÓµaÑuʽ
#uploadPreview {
width: 168px;
height: 168px;
background-position: center center;
background-size: cover;
border: 4px solid #fff;
-webkit-box-shadow: 0 0 0px 0px rgba(0, 0, 0, 0);
display: inline-block;<br>}
¿´ÏÂЧ¹u£º
È»ºo¾ÍÊÇдʼþÁË
$("#uploadImage").on("change", function(){
// µÃµ½Ò»¸o²Î¿¼ÎļþÁбi
var files = !!this.files ? this.files : [];
// Èç¹uûÓÐÑ¡ÔñÈκÎÎļþ,»oÕßûÓÐÎļþ¶Áµ½¾Í*µ»Ø
if (!files.length || !window.FileReader) return;
// Ö»ÓнøÐÐÑ¡ÔñµÄÎļþÊÇÒ»¸oÐÎÏo
if (/^image/.test( files[0].type)){
// ´´½¨Ò»¸oеÄFileReaderµÄʵÀý
var reader = new FileReader();
// ¶ÁÈ¡±¾µØÎļþ×÷Ϊһ¸oDataURL
reader.readAsDataURL(files[0]);
// µ±¼ÓÔØʱ,ͼÏñÊý¾ÝÉeÖÃΪ±³¾°µÄdiv
reader.onloadend = function(){
$("#uploadPreview").css("background-image", "url("+this.result+")");
}
}
});
ÕaÖ»ÊÇÒ»¸o¼oµ¥µÄÉÏ´«Ô¤ÀÀ£¬ÉÏ´«µ½ÎļþÖеĴ¦ÀiÒ³Ãae»¹Ã»ÓÐд£¬¸ÄÌi²¹ÉÏÍeÕuµÄÉÏ´«Í¼Æ¬´uÂe
¿´ÏÂÑ¡ÖÐͼƬµÄЧ¹u
ÕaÑu£¬ÎļþÉÏ´«ºÍͼƬԤÀÀ¾Í½aÊøÁË£¬ÕaÁ½¸o½aºÏһϾͿÉÒÔ×o³oͼƬµÄÉÏ´«ÁË£¬¹ýºoÎÒ»a¼ÌÐø²¹³aÍeÕuµÄ~~~