【发布时间】:2015-02-08 06:43:01
【问题描述】:
我想用php和ajax获取图片上传的临时名称。我得到了upolad图片的文件名。但不要获取图片上传的临时名称。我的代码如下。任何正文
main.php
<form action=" " method="POST" enctype="multipart/form-data">
<div class="form-group">
<label for="exampleInputFile">File Upload</label>
<input type="file" name="file" id="file" size="150">
<p class="help-block">Only Excel/CSV File Import.</p>
</div>
<button type="button" class="btn btn-default"
name="Import" value="Import" onclick="file_up()">
Upload</button>
</form>
<div id="upload_show" > </div>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
function file_up()
{
var file=$('#file').val();
$.ajax({
type: "POST",
url: 'first_ajax.php',
data:'file='+file,
success: function(msg)
{
$("#upload_show").html(msg);
}
});
}
</script>
first_ajax.php
<?php
echo $file1 = $_POST['file']; // for get file name
echo $file1 = $_POST['file']['tmp_name']; //for get temp name
?>
您能给我一个关于如何获取 $_FILES['file']['tmp_name'] 的建议吗?
【问题讨论】:
-
我需要 ajax 页面中的值 $_FILES["file"]["tmp_name"]。现在我得到了文件名。但不是 ajax 页面中的临时名称
-
我不给表单,我用onclick事件不提交
-
我已经发布了一个完整的图片上传教程它可以帮助你stackoverflow.com/questions/26861807/…