日期:2014-05-17 浏览次数:20642 次
<?php //第一个例子 require_once('../Public/CommandLine.php'); $isget = ($_SERVER['REQUEST_METHOD'] == 'GET') ? 1 : 0; if ($isget) { $html = <<<longs <html> <body> <form method="post" enctype="multipart/form-data" > 请选择文件:<input type="file" name="file1" > <br /> <input type="submit" value="提交" /> </form> </body> </html> longs; echo $html; } else { $file = $_FILES['file1']; $oldname = $file['tmp_name']; $result = move_uploaded_file($oldname, $file['name']);//可以随意替换名称 echo $file['name'] . '上传成功,请到当前文件夹下去检查'; }
<?php //第一个例子 require_once('../Public/CommandLine.php'); $isget = ($_SERVER['REQUEST_METHOD'] == 'GET') ? 1 : 0; if ($isget) { $html = <<<longs <html> <link href="ajaxfileupload.css" type="text/css" rel="stylesheet"> <script type="text/javascript" src="jquery-1.6.2.min.js"></script> <script type="text/javascript" src="ajaxfileupload.js"></script> <script type="text/javascript"> function ajaxFileUpload() { $("#loading") .ajaxStart(function(){ $(this).show(); }) .ajaxComplete(function(){ $(this).hide(); }); $.ajaxFileUpload ( { url:'2.php', secureuri:false, fileElementId:'fileToUpload', dataType: 'json', success: function (data, status) { alert('上传成功') }, error: function (data, status, e) { alert(e); } } ) return false; } </script> </head> <body> <div id="content"> <h1>Ajax文件上传示例</h1> <img id="loading" src="loading.gif" style="display:none;"> <form name="form" action="" method="POST" enctype="multipart/form-data"> <input id="fileToUpload" type="file" size="45" name="fileToUpload" class="input"> <b