The image upload with php is not working for some reason can somebody here solve the problem?
由于某种原因,有人在这里解决问题吗?
HTML code:
<td>Business Image<br><td> <input type="file" name="photo">
<td><input id="button" type="submit" name="submit" value="Setup"></td>
MYSQL:
Table structure for table markers
CREATE TABLE IF NOT EXISTS `markers` (
`id` int(11) NOT NULL,
`name` varchar(60) NOT NULL,
`phone` int(100) NOT NULL,
`address` varchar(80) NOT NULL,
`email` varchar(100) NOT NULL,
`link` varchar(200) NOT NULL,
`lat` float(10,6) NOT NULL,
`lng` float(10,6) NOT NULL,
`type` varchar(30) NOT NULL,
`days` varchar(100) CHARACTER SET utf8 NOT NULL,
`openingHours` varchar(255) NOT NULL,
`img` blob NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=51
The PHP Code
PHP代码
<?php
include ("../Connections/Connection.php");
if (isset($_POST["submit"])) {
$name = $_POST["name"];
$type = $_POST["type"];
$address = $_POST["address"];
$email = $_POST["email"];
$phone = $_POST["phone"];
$link = $_POST["link"];
$lng = $_POST["lng"];
$lat = $_POST["lat"];
$days = implode(";", $_POST['days']);
$openingHours = implode(";", $_POST['openingHours']);
$img = time().$_FILES['photo']['name'];
if (!move_uploaded_file($_FILES['photo']['tmp_name'],'../Uploads/'.$img)) die("error");
$sql = "INSERT INTO markers (name, type, address, email, phone, link, lng, lat, days, openingHours, img)
VALUES('$name', '$type', '$address', '$email', '$phone', '$link', '$lng', '$lat', '$days', '$openingHours', '$img')";
$query = mysql_query($sql);
if (!$query) {
die("Error : " . mysql_error());
}
if (empty($name) || empty($type) || empty($address) || empty($email) || empty($phone) || empty($lng) || empty($lat) || empty($days) || empty($openingHours) || empty($img)) {
echo "You did not fill out the required fields.";
die(); // Note this
}
echo "<center></center>";
}
?>
It works perfectly without the upload file button.. but when I add the photo field I got :
没有上传文件按钮它完美地工作..但是当我添加照片字段时,我得到了:
Notice: Undefined index: photo in C:\xampp\htdocs\Final\BackEnd\ShopSetup.php on line 56
注意:未定义的索引:第56行的C:\ xampp \ htdocs \ Final \ BackEnd \ ShopSetup.php中的照片
Notice: Undefined index: photo in C:\xampp\htdocs\Final\BackEnd\ShopSetup.php on line 57 error
注意:未定义的索引:第57行的C:\ xampp \ htdocs \ Final \ BackEnd \ ShopSetup.php中的照片错误
That was long but I couldn't make the explanation shorter
那很长,但我无法简化解释
1 个解决方案
#1
When uploading file data, you need to set the encoding on your <form>
element to multipart, e.g.:
上传文件数据时,需要将
<form action="upload.php" method="post" enctype="multipart/form-data">
#1
When uploading file data, you need to set the encoding on your <form>
element to multipart, e.g.:
上传文件数据时,需要将
<form action="upload.php" method="post" enctype="multipart/form-data">