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
<?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程序设计有所帮助。
您可能感兴趣的文章:
- php+html5使用FormData对象提交表单及上传图片的方法
- 两种php实现图片上传的方法
- php+html5实现无刷新图片上传教程
- thinkphp实现图片上传功能
- php上传图片生成缩略图(GD库)
- php上传图片并压缩的实现方法
- PHP实现图片上传并压缩
- php+ajax无刷新上传图片实例代码
- php修改上传图片尺寸的方法
- php上传图片客户端和服务器端实现方法
- PHP+jQuery+Ajax实现多图片上传效果
- php实现上传图片保存到数据库的方法
- PHP Yii框架之表单验证规则大全

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
