gpt4 book ai didi

php上传图片获取路径及给表单字段赋值的方法

转载 作者:qq735679552 更新时间:2022-09-28 22:32:09 25 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章php上传图片获取路径及给表单字段赋值的方法由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

本文实例讲述了php上传图片获取路径及给表单字段赋值的方法。分享给大家供大家参考,具体如下:

1. 调用方法例子

大图路径:

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

小图路径:

?
1
2
< 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 。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?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( "请选择要上传的文件" );
  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上传图片获取路径及给表单字段赋值的方法的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com