1

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

2 Answers 2

10

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">
Sign up to request clarification or add additional context in comments.

1 Comment

Oh my...it must be late or something. I thought i was going crazy - guess i just accidentally removed that or something. Oh well, thanks a ton for the help! I'll come back in about 8 minutes to "check" the answer and give you credit for the answer. Thanks again!
0

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

2 Comments

The above answer was my problem. Just forgot to put the enctype in the form.
memory_limitand max_execution_time are not referenced in php.net/manual/en/features.file-upload.post-method.php. Where did you get them from? EDIT: Now I see memory_limit is referenced at php.net/manual/en/ini.core.php#ini.post-max-size

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.