I would like to ask for help with file uploading over AJAX under Ubuntu, I have separate apache, mysql and php servers installed (not a lamp package bundle) and I want to add a file upload option to the form to be sent without page refreshing.
I have tried different approaches and so far had the best results with code posted by fellow stackoverflow user- Aitazaz Khan (posted as a response to question asked here file is not uploading in ajax php mysql).
To avoid the necessity of checking that post just to see the code I am reposting the code here, will post my problem below the code (code is the one posted originally by Vicky and Aitazaz Khan's script):
Form
<form name="multiform" id="multiform" action="process.php" method="POST" enctype="multipart/form-data">
name : <input type="text" name="name" id="name"/>
</br>
message : <input type="text" name="message" id="message" />
</br>
Image : <input type="file" name="file" id="file" />
</form>
<input type="button" id="multi-post" value="Run Code"></input>
<div id="multi-msg"></div>
Script
<script type="text/javascript">
$(document).ready(function(){
$("#multiform").submit(function(e)
{
var formObj = $(this);
var formURL = formObj.attr("action");
if(window.FormData !== undefined)
{
var formData = new FormData(this);
$.ajax({
url: formURL,
type: 'POST',
data: formData,
mimeType:"multipart/form-data",
contentType: false,
cache: false,
processData:false,
success: function(data, textStatus, jqXHR)
{
$("#multi-msg").html('<pre><code>'+data+'</code></pre>');
},
error: function(jqXHR, textStatus, errorThrown)
{
$("#multi-msg").html('<pre><code class="prettyprint">AJAX Request Failed<br/> textStatus='+textStatus+', errorThrown='+errorThrown+'</code></pre>');
}
});
e.preventDefault();
e.unbind();
}
});
$("#multi-post").click(function()
{
//sending form from here
$("#multiform").submit();
});
});
</script>
And PHP
<?php
mysql_connect("localhost","root","");
mysql_select_db("ajaxdatabase");
$name=$_POST["name"];
$message=$_POST["message"];
//storing file in filename variable
$fileName = $_FILES['file']['name'];
//destination dir
$to="image/".$fileName;
move_uploaded_file($_FILES['file']['tmp_name'],$to);
$query=mysql_query("INSERT INTO common(name,message,destination) values('$name','$message','$to') ");
if($query){
echo "Your comment has been sent";
}
else{
echo "Error in sending your comment";
}
?>
The problem is: after uploading a file I get the "Your comment has been sent" message and in the database I can see that all fields (including file's location) have been saved but physically the file is not saved.
My question is: do this has something to do with files/directories permissions? From what Vicky posted seems the code should be working correctly.
Posting on stackoverflow as in my opinion it has more to do with programming than with the Ubuntu system itself.
I would appreciate any help.
Best regards.