Php 脚本没有上传照片
好的,我有一个脚本,它将表单中的数据插入数据库并上传图片,它将所有信息插入数据库,但不上传图片 代码如下,我是PHP新手,非常感谢您的建议 谢谢:-)Php 脚本没有上传照片,php,mysql,Php,Mysql,好的,我有一个脚本,它将表单中的数据插入数据库并上传图片,它将所有信息插入数据库,但不上传图片 代码如下,我是PHP新手,非常感谢您的建议 谢谢:-) 使用以下代码。希望它能帮助你 if ($_FILES["photo"]["size"] < 30000) // specify file size here file size { if ($_FILES["photo"]["error"] > 0) { echo "Return Code: " . $_FILES["photo
使用以下代码。希望它能帮助你
if ($_FILES["photo"]["size"] < 30000) // specify file size here file size
{
if ($_FILES["photo"]["error"] > 0)
{
echo "Return Code: " . $_FILES["photo"]["error"] . "<br />";
}
else
{
if (file_exists("../restaurants/images/" . $_FILES["photo"]["name"]))
{
echo $_FILES["photo"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["photo"]["tmp_name"],"../restaurants/images/" . $_FILES["photo"]["name"]);
$rest_name=$_POST['rest_name'];
$address1=$_POST['address1'];
$address2=$_POST['address2'];
$town=$_POST['town'];
$postcode=$_POST['postcode'];
$open_time=$_POST['open_time'];
$halal=$_POST['halal'];
$deliver_areas=$_POST['deliver_areas'];
$deliver_time=$_POST['deliver_time'];
$type=$_POST['type'];
$photo=$_FILES["photo"]["name"] ;
mysql_select_db(restaurants);
//Writes the information to the database
mysql_query("INSERT INTO `restaurants` VALUES ('', '$rest_name', '$address1', '$address2', '$town', '$postcode', '$open_time', '$halal', '$deliver_areas', '$deliver_time', '$type', '$photo')") ;
if( mysql_errno() != 0)
{
// mysql error
// note: message like this should never appear to user, should be only stored in log
echo "Mysql error: " . htmlspecialchars( mysql_error());
die();
}
}
}
}
if($\u FILES[“photo”][“size”]<30000)//在此处指定文件大小文件大小
{
如果($_文件[“照片”][“错误”]>0)
{
回显“返回代码:”.$\u文件[“照片”][“错误”]。“
”;
}
其他的
{
如果(文件存在(“../restaurants/images/”$\u文件[“photo”][“name”]))
{
echo$\u文件[“照片”][“名称”]。“已存在。”;
}
其他的
{
移动上传的文件($\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\;
$rest\u name=$\u POST['rest\u name'];
$address1=$_POST['address1'];
$address2=$_POST['address2'];
$town=$_POST['town'];
$postcode=$_POST['postcode'];
$open\u time=$\u POST['open\u time'];
$halal=$_POST['halal'];
$deliver\u areas=$\u POST['deliver\u areas'];
$deliver\u time=$\u POST['deliver\u time'];
$type=$_POST['type'];
$photo=$_文件[“photo”][“name”];
mysql_select_db(餐厅);
//将信息写入数据库
mysql_查询(“插入到`餐厅'值中('''$rest_name','$address1','$address2','$town','$postcode','$open_time','$halal','$deliver_area',','$deliver_time','$type','$photo');
如果(mysql_errno()!=0)
{
//mysql错误
//注意:这样的消息永远不会出现在用户面前,应该只存储在日志中
echo“Mysql错误:”.htmlspecialchars(Mysql_error());
模具();
}
}
}
}
您不应该将文件插入数据库…我不确定脚本是否应该上载图片并将文件名发布到数据库中。对Destination文件夹的权限?仅为了测试,请尝试在目标文件夹上使用chmod 777并重新上载文件。$\u FILES['photo']
是数组,而不是文件名。
if ($_FILES["photo"]["size"] < 30000) // specify file size here file size
{
if ($_FILES["photo"]["error"] > 0)
{
echo "Return Code: " . $_FILES["photo"]["error"] . "<br />";
}
else
{
if (file_exists("../restaurants/images/" . $_FILES["photo"]["name"]))
{
echo $_FILES["photo"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["photo"]["tmp_name"],"../restaurants/images/" . $_FILES["photo"]["name"]);
$rest_name=$_POST['rest_name'];
$address1=$_POST['address1'];
$address2=$_POST['address2'];
$town=$_POST['town'];
$postcode=$_POST['postcode'];
$open_time=$_POST['open_time'];
$halal=$_POST['halal'];
$deliver_areas=$_POST['deliver_areas'];
$deliver_time=$_POST['deliver_time'];
$type=$_POST['type'];
$photo=$_FILES["photo"]["name"] ;
mysql_select_db(restaurants);
//Writes the information to the database
mysql_query("INSERT INTO `restaurants` VALUES ('', '$rest_name', '$address1', '$address2', '$town', '$postcode', '$open_time', '$halal', '$deliver_areas', '$deliver_time', '$type', '$photo')") ;
if( mysql_errno() != 0)
{
// mysql error
// note: message like this should never appear to user, should be only stored in log
echo "Mysql error: " . htmlspecialchars( mysql_error());
die();
}
}
}
}