Uploading Blog Article with Image to MySQL Table, Image Related Error
<p>The image file must not be uploading. I'm learning how to build a blog so I am starting simple to get the basic mechanics. There's a form to create an article on one page, a page for processing the form and reporting any errors, and another page for viewing short descriptions of all articles. There's also a file for viewing the uploaded image and another --coming-- to view an individual article in its entirety but they shouldn't be needed here. All the article data goes to a table in a MySQL database.</p>

<p>Whenever I upload the article, I get this message on the processing page: "Image not found in uploaded data"
I can remove the ! from this: if (!array_key_exists('image', $_FILES)) { throw new Exception('Image not found in uploaded data'); } ...in the processing file and get "File is not an uploaded file" ...sounds pretty similar. Connecting's not an issue. I'll paste in the relevant files and MySQL table.</p>

<p>This is the form file:</p>

<pre><code>&lt;?php
session_start(); #redirect
if (isset($_SESSION['usr_id']) &amp;&amp; !empty($_SESSION['usr_id']) ) {
} else {
    header('Location: notloggedin.php'); #redirect URL
}
?&gt;
&lt;?php include('header.php'); ?&gt;
&lt;div class="container blog-container"&gt;&lt;!-- Begin Blog Container--&gt;
    &lt;div class="row"&gt;&lt;!-- Begin Blog Row --&gt;
        &lt;div class="col-lg-9 col-sm-12 blog-main-content"&gt;&lt;!-- Begin Blog Content Div (Left Column) --&gt;
            &lt;div class="blog-header"&gt;&lt;!-- Begin Blog Content Header --&gt;
                &lt;p&gt;&lt;g16 class="blog-header-text"&gt;THE DATABASE DRIVEN BLOG BY ROBERT&lt;/g16&gt;&lt;/p&gt;
            &lt;/div&gt;&lt;!-- End Blog Content Header --&gt;
            &lt;div class="blog-content"&gt;&lt;!-- Begin - Main blog content in this div --&gt;
                &lt;br&gt;&lt;br&gt;
                &lt;p align="center"&gt;
        &lt;form metdod="post" action="article_process.php" enctype="multipart/form-data" name="form1"&gt;
            &lt;table widtd="100%" border="0" &gt;&lt;!-- TABLE TD'S AND TEXT REFUSE TO OBEY CSS!!! --&gt;
                &lt;tr&gt;
                    &lt;td align="right" valign="top" width="30%" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;"&gt;&lt;g16 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;"&gt;Title:&lt;/g16&gt;&lt;/td&gt;
                        &lt;td&gt;&lt;g14 style="font-size: 12pt;"&gt;&lt;input name="title" id="title" type="text" size="60" maxlengtd="75" /&gt;&lt;/g14&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td align="right" valign="top" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;"&gt;&lt;g16 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;"&gt;Date:&lt;/g16&gt;&lt;/td&gt;
                        &lt;td style=" padding-top: 5px;"&gt;&lt;g14 style="font-size: 12pt;"&gt;&lt;input type="text" disabled="disabled" value=&lt;?php echo date("Y-m-d"); ?&gt; name="cdate" id="cdate"  /&gt;&lt;/g14&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td align="right" valign="top" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;"&gt;&lt;g16 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;"&gt;Author:&lt;/g16&gt;&lt;/td&gt;
                        &lt;td style=" padding-top: 5px;"&gt;&lt;g14 style="font-size: 12pt;"&gt;&lt;input type="text" disabled="disabled" value=&lt;?php echo $_SESSION['usr_id']; ?&gt; name="author" id="author"  /&gt;&lt;/g14&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td align="right" valign="top" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;"&gt;&lt;g16 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;"&gt;Categories:&lt;/g16&gt;&lt;/td&gt;
                        &lt;td style=" padding-top: 5px;"&gt;&lt;g14 style="font-size: 12pt;"&gt;&lt;label for="category"&gt;&lt;/label&gt;
                            &lt;select name="category" id="category"&gt;
                                &lt;option value="Corruption"&gt;&lt;g14&gt;Corruption&lt;/g14&gt;&lt;/option&gt;
                                &lt;option value="Capitalism"&gt;&lt;g14&gt;Capitalism&lt;/g14&gt;&lt;/option&gt;
                                &lt;option value="Fascism"&gt;&lt;g14&gt;Fascism&lt;/g14&gt;&lt;/option&gt;
                            &lt;/select&gt;&lt;/g14&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td align="right" valign="top" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;"&gt;&lt;g16 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;"&gt;Short Description:&lt;/g16&gt;&lt;/td&gt;
                        &lt;td style=" padding-top: 5px;"&gt;&lt;g12 style="font-size: 12pt;"&gt;&lt;input name="desc" type="text" id="desc" size="60" maxlengtd="200" /&gt;&lt;/g12&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td align="right" valign="top" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;"&gt;&lt;g16 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;"&gt;Article:&lt;/g16&gt;&lt;/td&gt;
                        &lt;td style=" padding-top: 5px;"&gt;&lt;g12 style="font-size: 12pt;"&gt;&lt;textarea name="article" cols="59" rows="20"&gt;&lt;/textarea&gt;&lt;/g12&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td align="right" valign="top" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;"&gt;&lt;g16 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;"&gt;Upload File:&lt;/g16&gt;&lt;/td&gt;
                        &lt;td style=" padding-top: 5px;"&gt;&lt;g14 style="font-size: 12pt;"&gt;&lt;input type="file" name="image" /&gt;&lt;/g14&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td align="right" valign="top" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;"&gt;&lt;/td&gt;
                        &lt;td style=" padding-top: 5px;"&gt;&lt;g14 style="font-size: 12pt;"&gt;&lt;input name="submit" type="submit" value="Upload the Article" /&gt;&lt;g14&gt;&lt;input name="reset" type="reset" value="Reset" /&gt;&lt;/g14&gt;&lt;/td&gt;
                &lt;/tr&gt;
            &lt;/table&gt;
        &lt;/form&gt;
    &lt;/p&gt;
                &lt;br&gt;&lt;br&gt;
            &lt;/div&gt;&lt;!-- End - Main blog content in this div --&gt;
            &lt;div class="blog-header" style="vertical-align: middle; padding-bottom: 1px;"&gt;&lt;!-- Begin Blog Content Footer --&gt;
                &lt;p&gt;&lt;g16 class="blog-header-text"&gt;&lt;hr&gt;&lt;/g16&gt;&lt;/p&gt;
            &lt;/div&gt;&lt;!-- End Blog Content Footer --&gt;
        &lt;/div&gt;&lt;!-- End Blog Content Div (Left Column) --&gt;

&lt;!-- End of Body --&gt;
&lt;?php include('side-comments.php'); ?&gt;
&lt;?php include('footer.php'); ?&gt;
</code></pre>

<p>This is the file to process the form, article-process.php:</p>

<pre><code>&lt;?php
session_start();
?&gt;

&lt;?php include('header.php'); ?&gt;

&lt;?php
require_once('dbconnect.php');

function assertValidUpload($code)
{
    if ($code == UPLOAD_ERR_OK) {
        return;
    }

    switch ($code) {
        case UPLOAD_ERR_INI_SIZE:
        case UPLOAD_ERR_FORM_SIZE:
            $msg = 'Image is too large';
            break;

        case UPLOAD_ERR_PARTIAL:
            $msg = 'Image was only partially uploaded';
            break;

        case UPLOAD_ERR_NO_FILE:
            $msg = 'No image was uploaded';
            break;

        case UPLOAD_ERR_NO_TMP_DIR:
            $msg = 'Upload folder not found';
            break;

        case UPLOAD_ERR_CANT_WRITE:
            $msg = 'Unable to write uploaded file';
            break;

        case UPLOAD_ERR_EXTENSION:
            $msg = 'Upload failed due to extension';
            break;

        default:
            $msg = 'Unknown error';
    }

    throw new Exception($msg);
}

$errors = array();

try {
    if (!array_key_exists('image', $_FILES)) {
        throw new Exception('Image not found in uploaded data');
    }

    $image = $_FILES['image'];

    // ensure the file was successfully uploaded
    assertValidUpload($image['error']);

    if (!is_uploaded_file($image['tmp_name'])) {
        throw new Exception('File is not an uploaded file');
    }

    $info = getImageSize($image['tmp_name']);

    if (!$info) {
        throw new Exception('File is not an image');
    }
}
catch (Exception $ex) {
    $errors[] = $ex-&gt;getMessage();
}

if (count($errors) == 0) {
    // no errors, so insert the image
    $today = date("Y-m-d");
    $story = mysql_real_escape_string($_POST['article']);
    $query = sprintf(
        "insert into article (filename, mime_type, file_size, file_data, title, curr_date, author, description, category, story)
                values ('%s', '%s', %d, '%s', '$_POST[title]','$today', '$_POST[author]', '$_POST[desc]', '$_POST[category]', '$story')",
        mysql_real_escape_string($image['name']),
        mysql_real_escape_string($info['mime']),
        $image['size'],
        mysql_real_escape_string(
            file_get_contents($image['tmp_name'])));

    mysql_query($query, $conn);

    $id = (int) mysql_insert_id($conn);

    // finally, redirect the user to view the new image
    header('Location: thanks-article.php');
    exit;
}
?&gt;
&lt;div class="container blog-container"&gt;&lt;!-- Begin Blog Container--&gt;
    &lt;div class="row"&gt;&lt;!-- Begin Blog Row --&gt;
        &lt;div class="col-lg-9 col-sm-12 blog-main-content"&gt;&lt;!-- Begin Blog Content Div (Left Column) --&gt;
            &lt;div class="blog-header"&gt;&lt;!-- Begin Blog Content Header --&gt;
                &lt;p&gt;&lt;g16 class="blog-header-text"&gt;THE DATABASE DRIVEN BLOG BY ROBERT&lt;/g16&gt;&lt;/p&gt;
            &lt;/div&gt;&lt;!-- End Blog Content Header --&gt;
            &lt;div class="blog-content blog-content-message"&gt;&lt;!-- Begin - Main blog content in this div --&gt;
                &lt;div style="width: 60%; margin-left: auto; margin-right: auto; padding: 15px;"&gt;&lt;!-- Begin - Contains Error Messages --&gt;
                    &lt;p&gt;&lt;g16 style="font-size: 18pt;"&gt;
                        The following errors occurred:
                    &lt;/g16&gt;&lt;/p&gt;
                    &lt;g14 style="font-size: 14pt; color: #cc0000;"&gt;&lt;?php foreach ($errors as $error) { ?&gt;
                    &lt;ul&gt;
                            &lt;li&gt;
                                &lt;?php echo htmlSpecialChars($error) ?&gt;
                            &lt;/li&gt;
                        &lt;?php } ?&gt;
                    &lt;/ul&gt;&lt;/g14&gt;

                    &lt;p&gt;&lt;g14 style="font-size: 14pt;"&gt;
                        &lt;a href="index-blog.php"&gt;Try again&lt;/a&gt;
                    &lt;/g14&gt;&lt;/p&gt;
                &lt;/div&gt;&lt;!-- End - Contains Error Messages --&gt;
                &lt;div style="width: 40%; margin-left: auto; margin-right: auto; padding: 15px;"&gt;
                &lt;table&gt;
                    &lt;tr&gt;
                        &lt;td width="10" align="center" valign="middle"&gt;
                        &lt;a href="index-blog.php"&gt;&lt;img src='img/c-02.png' onmouseover="this.src='img/c-02-invert.png';" onmouseout="this.src='img/c-02.png';" /&gt;&lt;/a&gt;
                        &lt;/td&gt;
                    &lt;/tr&gt;
                &lt;/table&gt;
                &lt;/div&gt;
            &lt;/div&gt;&lt;!-- End - Main blog content in this div --&gt;
            &lt;div class="blog-header" style="vertical-align: middle; padding-bottom: 1px;"&gt;&lt;!-- Begin Blog Content Footer --&gt;
                &lt;p&gt;&lt;g16 class="blog-header-text"&gt;&lt;hr&gt;&lt;/g16&gt;&lt;/p&gt;
            &lt;/div&gt;&lt;!-- End Blog Content Footer --&gt;
        &lt;/div&gt;&lt;!-- End Blog Content Div (Left Column) --&gt;
        &lt;!-- End of Body --&gt;
&lt;?php include('side-comments.php'); ?&gt;
&lt;?php include('footer.php'); ?&gt;
</code></pre>

<p>This is the page you are taken to if the article is submitted successfully, thanks-article.php:</p>

<pre><code>&lt;?php
session_start();
?&gt;
&lt;?php include('header.php'); ?&gt;
&lt;div class="container blog-container"&gt;&lt;!-- Begin Blog Container--&gt;
    &lt;div class="row"&gt;&lt;!-- Begin Blog Row --&gt;
        &lt;div class="col-lg-9 col-sm-12 blog-main-content"&gt;&lt;!-- Begin Blog Content Div (Left Column) --&gt;
                        &lt;div class="blog-header"&gt;&lt;!-- Begin Blog Content Header --&gt;
                            &lt;p&gt;&lt;g16 class="blog-header-text"&gt;THE DATABASE DRIVEN BLOG BY ROBERT&lt;/g16&gt;&lt;/p&gt;
                        &lt;/div&gt;&lt;!-- End Blog Content Header --&gt;
                &lt;div class="blog-content blog-content-message"&gt;&lt;!-- Begin - Main blog content in this div --&gt;
                          &lt;p&gt;&lt;br&gt;&lt;/p&gt;
                          &lt;p style="text-align: center;"&gt;&lt;g18 style="font-size: 32pt; color: #004d00; text-shadow: 0 0 8px #ffff80, 0 0 16px #b3ff66;"&gt;YOU CREATED AN ARTICLE!&lt;/g18&gt;&lt;br&gt;&lt;/p&gt;
                    &lt;p style="text-align: center;"&gt;Click &lt;a href="view.php"&gt;here&lt;/a&gt; to view the image you uploaded.&lt;/p&gt;
                    &lt;p style="text-align: center;"&gt;Click &lt;a href="article.php"&gt;here&lt;/a&gt; to view your article.&lt;/p&gt;
                    &lt;p style="text-align: center;"&gt;Click &lt;a href="index-blog-view.php"&gt;here&lt;/a&gt; to view the article list.&lt;/p&gt;
                    &lt;div style="width: 40%; margin-left: auto; margin-right: auto; padding: 15px;"&gt;
                        &lt;table&gt;
                            &lt;tr&gt;
                                &lt;td width="auto" align="center" valign="middle"&gt;
                                    &lt;img src='img/c-08.png' /&gt;
                                &lt;/td&gt;
                            &lt;/tr&gt;
                        &lt;/table&gt;
                    &lt;/div&gt;
                &lt;/div&gt;&lt;!-- End - Main blog content in this div --&gt;
                &lt;div class="blog-header" style="vertical-align: middle; padding-bottom: 1px;"&gt;&lt;!-- Begin Blog Content Footer --&gt;
                    &lt;p&gt;&lt;g16 class="blog-header-text"&gt;&lt;hr&gt;&lt;/g16&gt;&lt;/p&gt;
                &lt;/div&gt;&lt;!-- End Blog Content Footer --&gt;
        &lt;/div&gt;&lt;!-- End Blog Content Div (Left Column) --&gt;
                    &lt;!-- End of Body --&gt;
&lt;?php include('side-comments.php'); ?&gt;
&lt;?php include('footer.php'); ?&gt;
</code></pre>

<p>This is the table from the database:</p>

<pre><code>CREATE TABLE `article` (
  `article_id` bigint(20) NOT NULL,
  `filename` varchar(255) NOT NULL,
  `mime_type` varchar(255) NOT NULL,
  `file_size` int(11) NOT NULL,
  `file_data` longblob NOT NULL,
  `title` varchar(75) NOT NULL,
  `curr_date` varchar(20) NOT NULL,
  `author` varchar(50) NOT NULL,
  `description` varchar(200) NOT NULL,
  `category` varchar(25) NOT NULL,
  `story` longblob NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
</code></pre>

<p>I can add that when I put it on the remote server I get "404 - File or directory not found." with all the same files and table... different connect script.
Thank You for Your Help!</p>