我正在尝试通过 ajax 发布表单数据
form1.php
我使用请求获取所有 URL 参数数据
$_REQUEST["Ename"];
$_REQUEST["eImg"];
要上传图片,我使用此代码http://www.9lessons.info/2011/08/ajax-image-upload-without-refreshing.html
在上面的链接中,你可以看到源代码,在 $_FILES['photoimg']['name']; 的地方,我使用 $_FILES['image']['name']; 但它没有上传文件并给出成功消息。
include('db.php');
session_start();
$session_id='1'; // User session id
$path = "uploads/";
我删除了标有 ** 的脚本
$valid_formats = array("jpg", "png", "gif", "bmp","jpeg");
**if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
{**
$name = $_FILES['image']['name'];
$size = $_FILES['image']['size'];
if(strlen($name)) {
list($txt, $ext) = explode(".", $name);
if(in_array($ext,$valid_formats)) {
if($size<(1024*1024)) { // Image size max 1 Mb
$actual_image_name = time().$session_id.".".$ext;
$tmp = $_FILES['image']['tmp_name'];
if(move_uploaded_file($tmp, $path.$actual_image_name)) {
mysql_query("UPDATE users SET profile_image='$actual_image_name' WHERE uid='$session_id'");
echo "<img src='uploads/".$actual_image_name."' class='preview'>";
} else {
echo "failed";
}
} else {
echo "Image file size max 1 MB";
}
} else {
echo "Invalid file format..";
}
} **else {
echo "Please select image..!";
exit();
}**