I´ve been looking at all the answers i could find in here, but none seems to work for me, not sure why.
I´m trying to upload a file using ajax, but the file never gets to the $_FILES array in PHP, i only makes it to the $_POST array but it won´t let me get the name or size of the file. I've tried every single solution answered here but none seems to solve my problem and i'm not sure why, i think there is something i'm not seeing. If anyone can help me that would be awesome.
THE HTML CODE
<form name='formuploadgraphic'>
<input type='file' name='archivo1' id='archivo1' onchange='subegraphic()'>
</form>
THE JS/AJAX CODE
function subegraphic()
{
var formData = new FormData();
formData.append("archivo1", $("#formuploadgraphic")[0]);
$.ajax({
url: "subegraphic.php",
type: "post",
data: formData,
cache: false,
contentType: false,
processData: false,
async: true
})
.done(
function(data)
{
alert(data);
}
);
}
THE PHP CODE
<?php
$upload_folder ='graphics';
$nombre_archivo = $_FILES['archivo1']['name'];
$tipo_archivo = $_FILES['archivo1']['type'];
$tamano_archivo = $_FILES['archivo1']['size'];
$tmp_archivo = $_FILES['archivo1']['tmp_name'];
$extension = pathinfo($_FILES['archivo1']['name'], PATHINFO_EXTENSION);
$archivador = $upload_folder . '/' . $nombre_archivo;
echo $nombre_archivo;
?>
This is the reply from the php if i use that code:
"
Notice: Undefined index: archivo1 in C:\xampp\htdocs\airpost\home\subegraphic.php on line 4
Notice: Undefined index: archivo1 in C:\xampp\htdocs\airpost\home\subegraphic.php on line 5
Notice: Undefined index: archivo1 in C:\xampp\htdocs\airpost\home\subegraphic.php on line 6
Notice: Undefined index: archivo1 in C:\xampp\htdocs\airpost\home\subegraphic.php on line 7
Notice: Undefined index: archivo1 in C:\xampp\htdocs\airpost\home\subegraphic.php on line 8
"
If anyone can tell what is the problem with my code that would be grate. Thx in advance.
PS: upload files is ON in the php.ini