Привет ползвам една upload форм с ajax,php,jquery обаче проблем ми е следния след като кача изображенито незнам как да подам променливата с името на изображението към jquery-to в индекс
ето и файловете който ползвам
- index.php
uploadPhoto.php
Понеже съм нов в използването на ajax с php ще съм благодарен за помоща
ето и файловете който ползвам
PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Basic Ajax and PHP tutorial</title>
<script type="text/javascript" src="Ajaxfileupload-jquery-1.3.2.js" ></script>
<script type="text/javascript" src="ajaxupload.3.5.js" ></script>
<link rel="stylesheet" type="text/css" href="Ajaxfile-upload.css" />
<script type="text/javascript" >
$(function(){
var btnUpload=$('#me');
var mestatus=$('#mestatus');
var files=$('#files');
new AjaxUpload(btnUpload, {
action: 'uploadPhoto.php',
name: 'uploadfile',
onSubmit: function(file, ext){
if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){
// extension is not allowed
mestatus.text('Файлът който се опитвате да качите е в непозволен формат.');
return false;
}
mestatus.html('<img src="ajax-loader.gif" height="16" width="16">');
},
onComplete: function(file, response){
//On completion clear the status
mestatus.text('Успешно добавихте изображението.');
//On completion clear the status
files.html('');
//Add uploaded file to list
if(response==="success"){
$("#me").hide();
$("#formats").hide();
} else{
$("#me").show();
$("#formats").show();
$('<li></li>').appendTo('#files').text(file).addClass('error');
}
}
});
});
</script>
</head>
<body>
<div id="me" class="styleall"><span style=" cursor:pointer;">Качи</span></span></div><span id="mestatus" ></span>
<span id="formats" style="font-weight: lighter;color: gray;"><i>Позволени формати: jpg, jpeg, png, gif</i></span>
</body>
</html>
PHP:
<?php
$uploaddir = './images/';
$allowed = array("jpeg","jpg","png","gif");
$filee = $_FILES['uploadfile']['name'];
$fileext = strtolower(substr($filee,strrpos($filee,".")+1));
$file_name= md5(uniqid());
$file = $uploaddir . $file_name;
$file = ''.$file.'.'.$fileext.'';
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {
$source_pic = $file;
$destination_pic = $file;
$max_width = 64;
$max_height = 64;
$src = imagecreatefromjpeg($source_pic);
list($width,$height)=getimagesize($source_pic);
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
if( ($width <= $max_width) && ($height <= $max_height) ){
$tn_width = $width;
$tn_height = $height;
}elseif (($x_ratio * $height) < $max_height){
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}else{
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
$tmp=imagecreatetruecolor($tn_width,$tn_height);
imagecopyresampled($tmp,$src,0,0,0,0,$tn_width, $tn_height,$width,$height);
imagejpeg($tmp,$destination_pic,100);
imagedestroy($src);
imagedestroy($tmp);
echo "success";
} else {
echo "error";
}
?>
Понеже съм нов в използването на ajax с php ще съм благодарен за помоща