PHP表单不上传文件

时间:2010-08-24 04:02:40

标签: php mysql forms file file-upload

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

请有人可以查看我的PHP代码,看看我是否遗漏了什么?非常感谢!!

表格代码:

<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");`

2 个答案:

答案 0 :(得分:8)

上传文件时将multipart/form-data enctype添加到表单

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

答案 1 :(得分:0)

您的php.ini中是否已启用file_uploads(或使用ini_set)? filesize是否大于php.ini中的upload_max_filesize配置选项?

也要看看其他人:

  • max_input_time设置
  • memory_limit的
  • 的max_execution_time
  • 的post_max_size