我使用以下PHP代码将图像上传到MySQL。当我点击提交没有任何反应。
include ("connect.php");
session_start();
$login = $_SESSION['wname'];
if((@$_POST['submit'])&&(isset($_FILES["myfile"]))){
// properties of the uploaded file
$name = $_FILES["myfile"]["name"];
$type = $_FILES["myfile"]["type"];
$size = $_FILES["myfile"]["size"];
$temp = $_FILES["myfile"]["tmp_name"];
$error = $_FILES["myfile"]["error"];
if($name){
die("Error uploading file! Code $error.");
} else {
$place = "avatars/$name";
move_uploaded_file($tmp_name,$place);
$query = mysql_query("UPDATE page SET pid_image_name = '$place' WHERE wname = '$login' ");
die("upload complete <a href='index.php'>View image</a>");
echo "Upload complete!";
}
} else {
die("select a file");
}
这是我的表格:
<form action='up.php' method='POST' enctype='multipart/form'>
<input type='file' name='myfile'>
<p> <input type='submit' name='submit' value="upload">
我做错了什么?
答案 0 :(得分:3)
在php.ini中检查的另一个重要参数是post_max_size。如果您设置upload_max_filesize&gt; post_max_size结果是,对于大小超过post_max_size但低于upload_max_filesize的文件,没有数据写入$ _POST或$ _FILES
答案 1 :(得分:2)
enctype="multipart/form-data" needs added to your form tag!
)答案 2 :(得分:1)
在您的HTML中,您有enctype="multipart/form-data"
吗?
像这样:
<form action='submit.php' method='post' enctype="multipart/form-data">
修改1 :
如果你这样做:
if(move_uploaded_file($tmp_name, $place)){
echo "did move file<br />";
}else{
echo "move failed<br />";
}
您将获得移动失败(或者我使用您的代码)
$temp
,但在move_uploaded_file
中你要求$tmp_name
所以这里有正确的代码:move_uploaded_file($temp, $place);
答案 3 :(得分:-1)
如果您看不到任何错误,请在php标记后面设置error_reporting(E_ALL);
来激活错误报告。