PHP表单不上传文件 [英] PHP form not uploading file

查看:136
本文介绍了PHP表单不上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个将表单插入数据库的信息。除了文件上传以外,这一切都是有效的。文件名需要放在数据库表的image列中,文件也需要放在目录中。有趣的是,这个上传者昨天工作。 :-S



请有人可以查看我的PHP代码,看看我是否失去了一些东西?
$ b

表格代码:

 < form name =upload_announcementmethod =postaction =PostAnnouncement.php> 
标题:(限制35个字符)< br />
< input type =textname =titlemaxlength =32style =width:200px; />< br />< br />
消息:(限制500个html字符)< br />
< textarea name =messagecols =60rows =20>< / textarea>< br />< br />
上传图像:(规格:.jpg格式,255像素×255像素,小于500kb)< br />
< br />< br />
开始日期:< br />
< input name =dateStarttype =textid =dateStartImg/>
< br />< br />
结束日期:< br />
< input name =dateEndtype =textid =dateEndImg/>
< br />< br />
< input type =hiddenname =customerIdvalue =<?php echo $ _COOKIE ['customerId'];?> />
< input type =submitname =uploadvalue =Upload Announcement/>
< / form>`

提交代码:< br />
`include('ConfigRead.php');

$ customerId = $ _COOKIE ['customerId'];
$ select = mysql_query('select user from where where customerId ='。$ customerId。'limit 1')or die('Error:'。mysql_error());
$ selectRow = mysql_fetch_array($ select);
$ filingName = $ selectRow ['filingName'];
$ imageFileName = $ _FILES ['image'] ['name']; ($($ _ FILES [image] [type] ==image / gif)
||($ _FILES [image] [type ($ _FILES [image] [type] ==image / pjpeg))
&&($ _FILES [ ($ _ $ FILES [image] [error]> 0){
header(location: ?Announcements.php文件=错误);
} else {
move_uploaded_file($ _ FILES [image] [tmp_name],
../Admin/CustomerFiles/Announcements/。$ filingName。/。$映像文件名称);
}
} else {
header(location:Announcements.php?file = error);


$ sql =INSERT INTO公告(customerId,filingName,title,message,image,dateStart,dateEnd)VALUES('$ _POST [customerId]','$ filingName', '$ _POST [标题]', '$ _ POST [消息]', '$映像文件名称', '$ _ POST [dateStart]', '$ _ POST [dateEnd]');

if(!mysql_query($ sql,$ connRead))
{
die('Error:'。mysql_error());
}

include('CloseConnRead.php');

header(location:ManageAnnouncements.php?add = success);`


解决方案

添加

 < form name =upload_announcement method =postenctype =multipart / form-dataaction =PostAnnouncement.php> 


I have a PHP form that is inserting information into a database. It all works except for the file upload. The filename needs to get placed inside the "image" column in the database table and the file needs to be put in the directory as well. Funny thing is that this uploader was working yesterday. :-S

Please can someone just review my PHP code and see if i am missing something?? Thanks so much!!

FORM CODE:

<form name="upload_announcement" method="post" action="PostAnnouncement.php">
Title: (limit 35 characters)<br />
<input type="text" name="title" maxlength="32" style="width:200px;" /><br /><br />
Message: (limit 500 html characters)<br />
<textarea name="message" cols="60" rows="20"></textarea><br /><br />
Upload Image: (Specs: .jpg format, 255px X 255px, and less than 500kb in size.)<br />
<input type="file" name="image" id="image" style="color:#fff;" />
<br /><br />
Start Date:<br />
<input name="dateStart" type="text" id="dateStartImg" />
<br /><br />
End Date:<br />
<input name="dateEnd" type="text" id="dateEndImg" />
<br /><br />
<input type="hidden" name="customerId" value="<?php echo $_COOKIE['customerId']; ?>" />
<input type="submit" name="upload" value="Upload Announcement" />
</form>`

SUBMIT CODE:<br />
`include('ConfigRead.php');

$customerId = $_COOKIE['customerId'];
$select = mysql_query('select filingName from user where customerId = '.$customerId.' limit 1') or die('Error: ' . mysql_error());
$selectRow = mysql_fetch_array( $select );
$filingName = $selectRow['filingName'];
$imageFileName = $_FILES['image']['name'];

if((($_FILES["image"]["type"] == "image/gif")
|| ($_FILES["image"]["type"] == "image/jpeg")
|| ($_FILES["image"]["type"] == "image/pjpeg"))
&& ($_FILES["image"]["size"] < 500000))
{
  if($_FILES["image"]["error"] > 0){
    header("location:Announcements.php?file=error");
  }else{
    move_uploaded_file($_FILES["image"]["tmp_name"],
    "../Admin/CustomerFiles/Announcements/" . $filingName . "/" . $imageFileName);
  }
}else{
  header("location:Announcements.php?file=error");
}

$sql="INSERT INTO announcements (customerId, filingName, title, message, image, dateStart, dateEnd) VALUES ('$_POST[customerId]','$filingName','$_POST[title]','$_POST[message]','$imageFileName','$_POST[dateStart]','$_POST[dateEnd]')";

if (!mysql_query($sql,$connRead))
  {
  die('Error: ' . mysql_error());
  }

include('CloseConnRead.php');

header("location:ManageAnnouncements.php?add=success");`

解决方案

Add the multipart/form-data enctype to your form when uploading files

<form name="upload_announcement" method="post" enctype="multipart/form-data" action="PostAnnouncement.php">

这篇关于PHP表单不上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆