国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

php上傳圖片獲取路徑及給表單字段賦值的方法

2024-05-04 23:42:28
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了php上傳圖片獲取路徑及給表單字段賦值的方法,涉及PHP文件傳輸與表單操作相關技巧,需要的朋友可以參考下
 

本文實例講述了php上傳圖片獲取路徑及給表單字段賦值的方法。分享給大家供大家參考,具體如下:

1. 調用方法例子:

大圖路徑:

<input type="text" name="bigImageURL" id="bigImageURL" value=""><iframe src="uppic.php?id=bigImageURL" width="600" height="25" frameborder="0" scrolling="no"></iframe>

小圖路徑:

<input type="text" name="smallImageURL" id="smallImageURL" value=""><iframe src="uppic.php?id=smallImageURL" width="600" height="25" frameborder="0" scrolling="no"></iframe>

2. uppic.php

<?phpheader("Content-Type:text/html;charset=GB2312");?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd"><HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>圖片上傳</TITLE><META http-equiv=Content-Type content="text/html; charset=gb2312"><META content="MSHTML 6.00.3790.4275" name=GENERATOR><style type="text/css"><!--input{border-width:1px;border:1px solid #bdbcbd;padding:3px 0 3px 5px;}.inputbut{padding-left:3px;padding-right:2px;border:1px solid #bdbcbd;background:#FFF url(../images/inputbut_bg.gif) left center repeat-x;font-size:12px;height:24px;}--></style></HEAD><BODY leftmargin=0 topmargin=0 style="font-size:12px"><?php$id=$_GET["id"];//echo "id==".$id;switch($_GET["action"]){case "up": upmovie($id); break;default: upinput($id); break;}function upinput($id){?><SCRIPT language=javascript>function check() { var strFileName=document.form.strPhoto.value; if (strFileName=="") {  alert("請選擇要上傳的文件"); document.form.strPhoto.focus();  return false; } return true;}</SCRIPT><form action="uppic.php?action=up&id=<?=$id?>" enctype="multipart/form-data" name="form" method="post" onsubmit="if (!check()) return false;"><input name="strPhoto" type="file" id="strPhoto" size="40"><input type="submit" name="Submit" value="上 傳" class=inputbut /></form></BODY><?php}function upmovie($id){ global $web_picdir; $savePath=dirname(__FILE__)."/".$web_picdir; $str = date('YmdHis'); if($_FILES['strPhoto']['name']!='') { $tmp_file=$_FILES['strPhoto']['tmp_name']; $file_types=explode(".",$_FILES['strPhoto']['name']); $file_type=$file_types[count($file_types)-1]; if(strtolower($file_type)!="jpg"&strtolower($file_type)!="gif"&strtolower($file_type)!="bmp"&strtolower($file_type)!="png"){  echo "<span style=/"color:red;line-height: 25px;/">格式錯誤請重新上傳<a href=# onclick=history.go(-1);>[返回]</a></span>";  exit; } $file_name=$str.".".$file_type; if(!copy($tmp_file,$savePath.$file_name)){ echo "<span style=/"color:red;line-height: 25px;/">上傳錯誤請重試!!<a href=# onclick=history.go(-1);>[返回]</a></span>"; }else{ //echo "<span style=/"olor:red;line-height: 25px;/">上傳成功</span><script>parent.document.getElementById(/"bigImageURL/").value=/"".$file_name."/"</script>"; echo "<span style=/"olor:red;line-height: 25px;/">上傳成功</span><script>parent.document.getElementById(/"{$id}/").value=/"".$file_name."/"</script>"; echo "<a href=# onclick=history.go(-1);>,若需要修改,請重新上傳</a>"; } }else{ echo "<span style=/"color:red;line-height: 25px;/">請選擇需要上傳的文件<a href=# onclick=history.go(-1);>[返回]</a></span>"; }}?>

注意: 不同的文本框 需要定義id,  iframe url :   uppic.php?id=文本框id

更多關于PHP圖片操作相關內容感興趣的讀者可查看本站專題:《PHP圖形與圖片操作技巧匯總

希望本文所述對大家PHP程序設計有所幫助。



注:相關教程知識閱讀請移步到PHP教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 凤翔县| 华阴市| 洛宁县| 开江县| 正镶白旗| 西青区| 宜宾市| 栾川县| 普安县| 台湾省| 伊宁市| 中卫市| 泗洪县| 阿荣旗| 彩票| 滕州市| 施甸县| 定州市| 威远县| 布尔津县| 当涂县| 鸡西市| 都昌县| 赞皇县| 来安县| 宣武区| 临颍县| 米脂县| 读书| 长岭县| 许昌县| 汝南县| 漯河市| 南雄市| 仙居县| 固原市| 乐陵市| 定边县| 布尔津县| 淮南市| 鄂州市|