I am trying to get the file in general I am working on an Ajax page. I can send the files name fine using a Post but when I try and retrieve the data about the file such as file size, type of file etc.. nothing is coming through with the name. If you will notice I use jQuery to post to the php file on submit so that is where I think the problem may lie.
This is the form code I am using:
Code:
<form method="post" enctype="multipart/form-data" name="brancato" id="brancato">
<input type="file" name="uploaded_file" id="uploaded_file">
<input type="submit" name="sendForm" id="sendForm" value="Upload">
</form>
this is the jQuery I coded:
Code:
$(document).ready(function() {
$("div#yes").hide().fadeOut(100);
$("div#no").hide().fadeOut(100);
$("form#brancato").submit(function(){
$.post("upload.php",{ uploaded_file: $("#uploaded_file").val()},
function(xml) {
if($("status",xml).text() == "0")
{
$("div#yes").hide();
$("div#no").fadeIn(300);
}
else if($("status",xml).text() == "1")
{
$("div#no").hide();
$("div#yes").fadeIn(300);
}
});
return false;
});
});
and this is the php page I coded to work with the file info:
Code:
///
// UPLOAD FILE //
///
$folder = "uploads/";
$folder = $folder . basename( $_FILES['uploaded_file']['name']);
$upload_size = $_FILES['uploaded_file']['size'];
$error = $_FILES['uploaded_file']['error'];
// CHECK IF INPUT WAS A VALID FILE //
$input = $_POST['uploaded_file'];
list($garbage,$extension) = split('[.]',$input,2);
$yes = 0;
switch ($extension)
{
case "zip":
$yes = 1;
break;
case "rar":
$yes = 1;
break;
case "jpg":
$yes = 1;
break;
default:
$yes = 2;
break;
}
//
///
// UPLOAD //
///
if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $folder))
{
$yes = 1;
}
else
{
$yes = 0;
}
if($yes == 1)
{
header( "Location: index.php?upload=yup" ) ;
}
if($yes == 0)
{
header( "Location: index.php?upload=nope" ) ;
}
if($yes == 2)
{
header( "Location: index.php?upload=invalid_file" ) ;
}
?>
I don't really need to use Ajax to do this, I just want to for learning purposes and to see if it can be done.
|