首頁  >  文章  >  後端開發  >  PHP檔案傳輸與表單操作

PHP檔案傳輸與表單操作

墨辰丷
墨辰丷原創
2018-06-05 13:47:431222瀏覽

本篇文章主要介紹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

##

<?php
header("Content-Type:text/html;charset=GB2312");
?>
<!DOCTYPE HTML>
<HTML>
<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(&#39;YmdHis&#39;);
 if($_FILES[&#39;strPhoto&#39;][&#39;name&#39;]!=&#39;&#39;)
 {
 $tmp_file=$_FILES[&#39;strPhoto&#39;][&#39;tmp_name&#39;];
 $file_types=explode(".",$_FILES[&#39;strPhoto&#39;][&#39;name&#39;]);
 $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>";
 }
}
?>

總結:以上就是這篇文章的全部內容,希望能對大家的學習有所幫助。

相關推薦:

PHP實作將頁面中點擊數量高的連結進行高亮顯示的方法

PHP表單資料寫入MySQL資料庫的方法

PHP中OpCode原理詳解

############ ##########

以上是PHP檔案傳輸與表單操作的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn