phpappend
代码如下
form action="upload.php" id="form1" name="form1" enctype="multipart/form-data" method="post" target="uploadIframe"> <!--上传图片页面 --> </form> <iframe name="uploadIframe" id="uploadIframe" style="display:none"></iframe>
然后后台处理完上传图片逻辑后返回给前台,利用ajax修改当前页面DOM对象实现无刷新上传图片的友好功能。
实例
代码如下
a.html <form enctype="multipart/form-data" action="a.php" target="ifram_sign" method="POST"> <input name="submit" id="submit" value="" type="hidden"> <label>上传文件: <input name="test_file" type="file" id="test_file" size="48"></label> <input type="image" value="立即上传" id="submit_btn"> </form><iframe name="ifram_sign" src="" frameborder="0" height="0" width="0" marginheight="0" marginwidth="0"></iframe>
php代码:
代码如下
<?php
if ($_files["test_file"]["error"] > 0)
{
echo "Error: " . $_files["test_file"]["error"] . "<br />";
}
else
{
//这里的判断图片属性的方法就不写了。自己扩展一下。
$filetype=strrchr($_files["test_file"]["name"],".");
$filetype=substr($filetype,1,strlen($filetype));
$filename="img/".time("YmdHis").".".$filetype;
move_uploaded_file($_files["test_file"]["tmp_name"],$filename);
echo '<script >alert(1)</script>';
$return="parent.document.getElementByIdx_x('mpic".$pageset_id."').innerhtml='".$dataimgpath."'";
echo "<script >alert('上传成功')</script>";
echo "<script>{$return}</script>";
}
?>
其实jquery ajax图片异步上传
html:
<!DOCTYPE html PUBLIC "-//W3C//dtd Xhtml 1.0 transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en_US" xml:lang="en_US">
<head>
<title>图片异步上传</title>
</head>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<link type="text/css" rel="stylesheet" href="css/index.css">
<body>
<div class="frm">
<form name="uploadFrom" id="uploadFrom" action="upload.php" method="post" target="tarframe" enctype="multipart/form-data">
<input type="file" id="upload_file" name="upfile">
</form>
<iframe src="" width="0" height="0" style="display:none;" name="tarframe"></iframe>
</div>
<div id="msg">
</div>
</body>
</html>
index.js
$(function(){
$("#upload_file").change(function(){
$("#uploadFrom").submit();
});
});
function stopSend(str){
var im="<img src='upload/images/"+str+"'>";
$("#msg").append(im);
}
upload.php
<?php
$file=$_files['upfile'];
$name=rand(0,500000).dechex(rand(0,10000)).".jpg";
move_uploaded_file($file['tmp_name'],"upload/images/".$name);
//调用iframe父窗口的js 函数
echo "<script>parent.stopSend('$name')</script>";
?>
异步上传图片几种方法
‘贰’ PHP的页面查询结果在本页显示,而不是另外一页显示
想要在本页显示,估计可以采用ajax,你可以先了解下它,然后找一下相关的例子。ajax是一种页面局部刷新技术,就是你可以使用js来获取一个页面的内容,然后动态地显示在页面上。
你可以看看jquery封装好的ajax方法,然后按照实例修改下你的代码,应该就可以实现你想要的效果了。
将ajax的请求url改写成另一个页面的地址,然后将返回的内容使用append等方法拼接到页面上就可以了。
‘叁’ php编程输出100以内的素数
素数就是只能被 1 和它本身所整除的数。从2~100,逐个判断素数,如果是素数,就打印,否则不打印。
源代码如下:
#coding:utf-8
for i in range(2,101):
fg = 0
for j in range(2,i-1):
if i%j == 0:
fg = 1
break
if fg == 0:
print(i)
i = 2
c = []
while i <= 100:
j = 2
while j <= i:
if i % j == 0:
if i == j:
c.append(i)
break
j += 1
i += 1
print(c)
(3)phpappend扩展阅读
a~b之间的素数的代码
def su(a,b):
for i in range(a,b):
n = False #默认不是素数,如果是素数,跳出循环
for j in range(2,int(i**0.5)):
if i%j == 0:
n = True
break
if n == False:
print(i,end=" ")
su(100,200)
‘肆’ PHP文件写入的几种方法
通过fwrite
$file = fopen("test.txt","a+"); //次方法会自动生成文件test,txt,a表示追加写入,
//w代表替换写入 fwrite($file,"写入代码"); fclose($file);
file_put_content()方法写入
file_put_contents("test.txt","奥斯卡老\r\n顿积分");//这里说一下\r\n在双引号下
//才会换行如果单引号就识别不了
//如果想追加写入内容,这个函数还有第三个参数FILE_APPEND
‘伍’ php 数组追加
在PHP里面,往数组中追加元素最简单的方法是使用[]赋值,例如需要在$arr添加一条123的语句是$arr[]=123,可以参考下面的代码:
<?php
$arr=[123,456];
print_r($arr);
$arr[]=789;
print_r($arr);
?>
(5)phpappend扩展阅读:
PHP函数
constant() 函数返回常量的值。
connection_status() 函数返回当前的连接状态。
connection_aborted() 函数检查是否断开客户机。
zip_read() 函数读取打开的 zip 档案中的下一个文件。
zip_open() 函数打开 ZIP 文件以供读取。
zip_entry_read() 函数从打开的 zip 档案项目中获取内容。
zip_entry_open() 函数打开一个 ZIP 档案项目以供读取。
‘陆’ php 怎么在文件尾部写入内容
可以看看error_log函数和file_put_contents函数(追加模式FILE_APPEND)
‘柒’ php怎样来建立一个表格呀
1、首先创建一个html文件,编写上基本的代码,在head头部中引入jquery路径,用于调用其中封装的方法。
‘捌’ PHP选中某商品,其属性连带过来
用到了jquery,当你输入一个字以后,使用jquery检测你的下拉框是否change,如果有,则触发php函数,根据输入的内容到数据库查找出来,已json方式传过来,然后使用$.each将json读出,将信息append到下拉菜单后面。
‘玖’ php中append是什么意思
就是追加的意思
‘拾’ php如何将一个txt文件的内容追加到另一个txt文件里
打开读取txt1 用追加的方式写进txt2就行了啊