I want to create an uploadscript. This is my JS:
$("#subUpload").live("change", function(){
var fd = new FormData();
var file = this.files[0];
fd.append("subUpload", file);
$.ajax({
type: 'POST',
cache: false,
url: "script.php",
processData: false,
contentType: false,
data: fd,
success: function(data){
alert("Message: " + data);
}
});
});
And this is my PHP:
<?php
if($_FILES['subUpload']['error'] == 0){
if(is_dir('./files')){
if(move_uploaded_file($_FILES['subUpload']['tmp_name'], '/files/'.$_FILES['subUpload']['tmp_name'])){
echo"UPLOADED";
}else{
echo"FAIL";
}
}
else{
echo "Uncorrect Path";
}
}
else{
echo $_FILES['subUpload']['error'];
}
?>
I always get the message “FAIL”.
I’ve set the folder permission to 777.
Any ideas?
you need to give a name to that file not just the folder
see http://php.net/manual/fr/function.move-uploaded-file.php
if more problem check
is_dir('/files')until you find the correct way to point to it