I have a problem with my upload file function. I'm following this website to create the upload form to upload a text file and i just modify it a little. Here's the code:
upload_form.php :
//the jquery script is still the same with the website
.....
echo "
<form action='processupload.php' method='post' enctype='multipart/form-data' id=MyUploadForm>
<input name='FileInput' id='FileInput' type='file' />
<input type='submit' id='submit-btn' value='Upload' />
<img src='images/ajax-loader.gif' id='loading-img' style='display:none;' alt='Please Wait'/>
</form>
<div id='progressbox' ><div id='progressbar'></div ><div id='statustxt'>0%</div></div>
<div id='output'></div>
";
processupload.php :
<?php
if(isset($_FILES["FileInput"]) && $_FILES["FileInput"]["error"]== UPLOAD_ERR_OK)
{
############ Edit settings ##############
//$UploadDirectory = '/impfile'; //specify upload directory ends with / (slash)
##########################################
//check if this is an ajax request
if (!isset($_SERVER['HTTP_X_REQUESTED_WITH'])){
die();
}
//Is file size is less than allowed size.
if ($_FILES["FileInput"]["size"] > 5242880) {
die("File size is too big!");
}
//allowed file type Server side check
switch(strtolower($_FILES['FileInput']['type']))
{
case 'text/plain':
break;
default:
die('Unsupported File!'); //output error
}
$File_Name = $_FILES['FileInput']['name'];
if(move_uploaded_file($_FILES['FileInput']['tmp_name'], "/impfile/".$File_Name ))
{
die('Success! File Uploaded.');
}else{
die('error uploading File!');
}
}
else
{
die('Something wrong with upload! Is "upload_max_filesize" set correctly?');
}
The problem is the feedback always showing error
die('error uploading File!');
I think the problem isn't from the code, because I can't found the php.ini in the same path that phpinfo showed me. I already set the folder (impfile) to be writeable too.
Can someone show me where did I do wrong in the code? Or maybe the php.ini? If the php.ini is the problem, how can I add the php.ini? Or maybe there's something else?
Every help would be appreciated. Thank you.