我试图将单个文件发送到服务器而无需更改网页。我决定使用这个插件:http : //cmlenz.github.com/jquery-iframe-transport/ 我很困惑如何在不更改网页的情况下进行上传...uploadimg.php 返回:
<br />
<b>Notice</b>: Undefined index: photo in <b>C:\website\uploadimg.php</b> on line <b>2</b><br />
<br />
<b>Notice</b>: Undefined index: photo in <b>C:\website\uploadimg.php</b> on line <b>3</b><br />
<img src="userimg/" />
我的文件:
postAd.php
<html>
<head>
<script src="jquery.js"></script>
<script src="jquery-iframe-transport.js"></script>
<script>
$(document).ready(function(){
$('#photo1').on('change', function(){
$.ajax({
url: "uploadimg.php",
files: $("#photo1:file"),
iframe: true,
processData: false
}).done(function(data){
console.log(data);
});
});
});
</script>
</head>
<body>
<input type='file' name='photo' id='photo1' /></br>
</body>
</html>
上传img.php
<?php
$file_tmp = $_FILES['photo']['tmp_name'][0];
$file = $_FILES['photo']['name'][0];
move_uploaded_file($file_tmp, "userimg/$file");
echo '<img src="userimg/' .$file .'" />';
?>