首先,用户在 id 的帮助下单击此按钮,我得到一个图像名称
表单.php
<form name="frm1" action="3.php" method="POST" enctype="multipart/form-data">
<div class="upload">
<input type="hidden" name="r" value="father">
<input type="hidden" name="id" value="<?=$id?>">
<input type="hidden" name="page" value="<?=$a?>">
<input type="file" name="uploadPic" onchange="frm1.submit();" />
</div>
</form>
上传.php
<?php
if(isset($_POST['pic'])) {
//echo $_POST['pic'] ;
$upload=false;
$baseName = basename($_POST['pic']);
$baseName=uniqid().'_'.$baseName;
//echo $baseName;
$toret = array("result" => "","img"=>"");
if (file_exists("./upload-pics/".$baseName))
$uploadResponse = "exists";
else {
move_uploaded_file('./upload-pics/' .$baseName);
$upload=true;
}
}
?>
pop.js
$(".upload").on("click", function () {
console.log("page");
$(".upload").on("change", function () {
var fr =$("#r").val();
var fr1 =$("#r1").val();
var fr2 =$("#r2").val();
var fr3 =$("#upload").val();
//console.log("page"+fr+fr1+fr2+fr3);
$.post("upload.php", {
"pic": fr3}, function (data) {
console.log(eval(data));
if (data.result == "1") {
console.log("getresult");
//webpopup();
} else {
alert("Please try again.");
}
}, "json");
});
});
我从pop.js获取图片名称之后,我得到了图片名称,我想将它保存在我的文件夹中,即上传图片。但是图像没有保存在所需的文件夹中。