简体   繁体   中英

PHP form not uploading file

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

上传文件时,将multipart / form-data编码添加到表单中

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

Do you have file_uploads enabled in your php.ini (or using ini_set )? Is the filesize larger than the upload_max_filesize configuration option in php.ini?

Look into these others, too:

  • max_input_time
  • memory_limit
  • max_execution_time
  • post_max_size

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM