php上傳圖片獲取路徑及給表單字段賦值的方法
本文實(shí)例講述了php上傳圖片獲取路徑及給表單字段賦值的方法。分享給大家供大家參考,具體如下:
1. 調(diào)用方法例子:
大圖路徑:
<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
<?php
header("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("請(qǐng)選擇要上傳的文件");
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;/">格式錯(cuò)誤請(qǐng)重新上傳<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;/">上傳錯(cuò)誤請(qǐng)重試?。?lt;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);>,若需要修改,請(qǐng)重新上傳</a>";
}
}else{
echo "<span style=/"color:red;line-height: 25px;/">請(qǐng)選擇需要上傳的文件<a href=# onclick=history.go(-1);>[返回]</a></span>";
}
}
?>
注意: 不同的文本框 需要定義id, iframe url : uppic.php?id=文本框id
更多關(guān)于PHP圖片操作相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《PHP圖形與圖片操作技巧匯總》
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
相關(guān)文章
關(guān)于查看MSSQL 數(shù)據(jù)庫(kù) 用戶每個(gè)表 占用的空間大小
本篇文章是對(duì)查看MSSQL數(shù)據(jù)庫(kù)用戶每個(gè)表占用的空間大小進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
PHP向socket服務(wù)器收發(fā)數(shù)據(jù)的方法
這篇文章主要介紹了PHP向socket服務(wù)器收發(fā)數(shù)據(jù)的方法,分析了socket收發(fā)數(shù)據(jù)的方法,并介紹了socket常用函數(shù),需要的朋友可以參考下2015-01-01
PHP7導(dǎo)出Excel報(bào)ERR_EMPTY_RESPONSE解決方法
在本篇文章中小編給大家整理了關(guān)于PHP7導(dǎo)出Excel報(bào)ERR_EMPTY_RESPONSE的解決方法,需要的朋友們學(xué)習(xí)下。2019-04-04
字符串長(zhǎng)度函數(shù)strlen和mb_strlen的區(qū)別示例介紹
strlen和mb_strlen的區(qū)別,但是對(duì)于一些初學(xué)者來(lái)說(shuō),如果不看手冊(cè),也許不太清楚其中的區(qū)別,下面與大家分享下兩者之間的區(qū)別2014-09-09
在PHP程序中運(yùn)行Python腳本(接收數(shù)據(jù)及傳參)的方法詳解
這篇文章主要為大家詳細(xì)介紹一下,如何在php程序中運(yùn)行Python腳本以及如何使用python返回josn數(shù)據(jù)供php使用,感興趣的小伙伴可以了解一下2022-09-09
PHP面向?qū)ο蟪绦蛟O(shè)計(jì)__tostring()和__invoke()用法分析
這篇文章主要介紹了PHP面向?qū)ο蟪绦蛟O(shè)計(jì)__tostring()和__invoke()用法,結(jié)合實(shí)例形式分析了__tostring()和__invoke()功能、用法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2019-06-06
如何批量替換相對(duì)地址為絕對(duì)地址(利用bat批處理實(shí)現(xiàn))
你的url鏈接是相對(duì)路徑你想把他批量替換成絕對(duì)路徑該怎么做呢?下面與大家分享下具體的實(shí)現(xiàn)思路及代碼,只需點(diǎn)擊bat文件,全部頁(yè)面里的相對(duì)地址就會(huì)變成絕對(duì)地址了2013-05-05

