I am having problem uplaoding file, here are my codes: Any help? Thanks!
test.html
function insertPhoto()
{
var description = document.getElementById('description').value;
var image = document.getElementById('photo').value;
var url = "ajax_insert.php?action=add&image="+image+"&description="+description;
var ajaxRequest = ajax_obj();
ajaxRequest.onreadystatechange = function() {
if(ajaxRequest.readyState == 4){
document.getElementById("msgbox").innerHTML=ajaxRequest.responseText;
}
}
ajaxRequest.open("GET", url, true);
ajaxRequest.send(null);
return false;
}
<div align="center">
<div class="top" >
<div>
Decription <input name="description" type="text" id="description" value="" maxlength="20" />
</div>
<div style="margin-top:5px" >
Image
<input name="photo" type="file" id="photo" value="" maxlength="20" />
</div>
<div class="buttondiv">
<input name="button" type="button" value="Upload" onclick="return insertPhoto()" style="margin-left:-10px; height:23px" />
<span id="msgbox" style="display:none"></span>
</div>
</div>
</div>
ajax_insert.php
<?php
mysql_connect('localhost','root','');
mysql_select_db('priceless');
define('DIR_IMAGE','images/');
$image = $_GET['image'];
$description = $_GET['description'];
$dbtable = 'photos';
$action = $_GET['action'];
if($action == 'add'){
$photo = '';
if ($_FILES[$image]['name']) {
$aray = explode(".",$_FILES[$image]['name']);
$ext = $aray[count($aray)-1];
$photo = date('Ymdhis').'.'.$ext;
move_uploaded_file($_FILES[$image]['tmp_name'],DIR_IMAGE.$photo);
}
$data = array(
'image'=> $photo,
'description'=> $description
);
$values = array();
foreach($data as $show){
$values[] = $show;
}
$query = "INSERT INTO ".$dbtable." (`".implode("`,`",array_keys($data))."`) values ('".implode("','",array_values($values))."')";
if ($result= mysql_query($query) or die(mysql_error())) {
echo "You have Sucessfully Upload Photo!";
}
}
?>