For saving a document/image in PHP, I am using move_uploaded_file($tmp, "location").
I'm getting the value of the document/image while the file is changing, so I got the file name, but I can't create tmp_name, because I'm getting name in the following way:
HTML:
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="file" id="upload" onChange="change(this.value)" />
<input type="submit" name="chk" value="Submit" />
<div id="div"></div>
</form>
JavaScript:
<script src="js/jquery1.js"></script>
<script>
function change(val){
$.ajax({
url:"filecheck.php?id=" + val,
success:function(res){
alert(res);
}
});
}
PHP: filecheck.php
mysql_connect("localhost","root","");
mysql_select_db("newdatabase");
if(isset($_GET['id']))
{
$name=$_GET['id'];
$tmp=$_GET['id']['tmp_name']; //here i need temp file name
move_uploaded_file($tmp, "C:/xampp/htdocs/jerome/project/newimage/".$name);
echo $name;
}
If I get the filename by $_FILES['file']['name'], it means I can get $_FILES['file']['tmp_name'], but I can't get by this way. Can you please give me a suggestion on how to get $_FILES['file']['tmp_name']?
$_GETand not$_FILES..... That will be your issue.$_FILESarray for this (sanwebe.com/2012/06/ajax-file-upload-with-php-and-jquery)onChangeevent doesn't mean that you are uploading a file. So$_FILESwill be empty at that time. Certainly you are doing it wrong.