Jump to content

i have problem with php+AJAX upload Files


kfir91

Recommended Posts

its my ajax code :

function uploadFile(dir) {
http.open("POST", "mod/filesManager/uploadFile.php",true);
http.onreadystatechange = function() {
	if(http.readyState == 4){
		alert(http.responseText);
		showManager(dir);
	}
}
http.send(null);
}

 

its uploadFile.php file :

<?php
error_reporting(0);
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
header("Content-type: text/html; charset=windows-1255");
include("../db.php");
include("../functions.php");
$uploaddir = security($_GET['dir']);
$uploadfile = "".$uploaddir." / ".basename($_FILES['filename']['name'])."";

echo "<p>";

if (move_uploaded_file($_FILES['filename']['tmp_name'], $uploadfile)) {
  echo "File is valid, and was successfully uploaded.\n";
} else {
   echo "Upload failed";
}

echo "</p>";
echo '<pre>';
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";



?>

 

now in php file the $_FILES empty why i need to do ?

You should check out this link:

http://stackoverflow.com/questions/543926/is-it-possible-to-ajax-a-file-upload/543927#543927

 

Basically you can't set the enctype with AJAX so you have to do a workaround either with an iframe or flash

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.