-1

以下は私のコードです:

    <?php 
    require_once("includes/initialize.php");
    if (!$session->is_logged_in()) { redirect_to("../index.php"); }
    include_template("admin_header.php");
    $product = new Products;
?>
<?php
    $upload_errors = array(
        // http://www.php.net/manual/en/features.file-upload.errors.php
        UPLOAD_ERR_OK               => "No errors.",
        UPLOAD_ERR_INI_SIZE     => "Larger than upload_max_filesize.",
      UPLOAD_ERR_FORM_SIZE  => "Larger than form MAX_FILE_SIZE.",
      UPLOAD_ERR_PARTIAL        => "Partial upload.",
      UPLOAD_ERR_NO_FILE        => "No file.",
      UPLOAD_ERR_NO_TMP_DIR => "No temporary directory.",
      UPLOAD_ERR_CANT_WRITE => "Can't write to disk.",
      UPLOAD_ERR_EXTENSION  => "File upload stopped by extension."
    );

    if(isset($_POST['submit'])) {
        if($_POST['productname'] == "" || $_POST['price'] == "" || $_POST['origin'] == "" || $_POST['description'] == "") {
            $message = "All fields are compulsary";
        } else {
            $errors = array();
            $now = time();
            $product->product_name  = $_POST['productname'];
            $product->price         = $_POST['price'];
            $product->origin        = $_POST['origin'];
            $product->description   = $_POST['description'];
            $product->img1          = $now."_".basename($_FILES['img1']['name']);
            $product->img2          = ($now+1)."_".basename($_FILES['img2']['name']);
            $product->visibility    = $_POST['visibility'];

            // process the form data
            $tmp_file = $_FILES['img1']['tmp_name'];
            $target_file = $product->img1;
            $tmp_file1 = $_FILES['img2']['tmp_name'];
            $target_file1 = $product->img2;
            $upload_dir = "images";

            // move_uploaded_file will return false if $tmp_file is not a valid upload file 
            // or if it cannot be moved for any other reason
            if(move_uploaded_file($tmp_file, $upload_dir."/".$target_file) && move_uploaded_file($tmp_file1, $upload_dir."/".$target_file1)) {
                $product->create();
                $message = "Product uploaded successfully. <br />";
            } else {
                                echo "<pre>".print_r($_FILES,true)."</pre>";
                $error = $_FILES['file_upload']['error'];
                $message = $upload_errors[$error];
            }
        }
    }
?>
  <tr>
    <td bgcolor="989797"><table width="1000" border="0">
      <tr bgcolor="#999999">
        <th width="750" valign="top" bgcolor="#999999" scope="col"><table width="100%" cellspacing="0" id="bodytable">
          <tr>
          <td></td>
          </tr>
          <tr class="bodytitle">
            <td colspan="2" valign="top"><strong>Add Product!!</strong></td>
          </tr>
          <tr>
            <td width="100%" valign="top"><div id="text2">
              <div>
                <table width="100%" cellspacing="0">
                  <tr>
                    <td colspan='2'>&nbsp;
                        <?php
                            if(isset($message)) {
                                echo "<font size='2'>".$message."</font>";
                            }
                        ?>
                    </td>
                  </tr>
                  <tr>
                    <td align='left' colspan='2'><font size='2'>File Size must be less than 1mb</font></td>
                  </tr>
                  <tr>
                    <td>&nbsp;</td>
                  </tr>
                  <tr>
                   <form name="form1" enctype="multipart/form-data" action="addproduct.php" method="POST">
                   <input type="hidden" name="MAX_FILE_SIZE" value="1048576" />
                   <td align='left'><font size='2'>Product Name:</font></td>
                   <td align='left'><input name='productname' type='text' /></td>
                     </tr>
                     <tr>
                       <td align='left'><font size='2'>Price:</font></td>
                       <td align='left'><input name='price' type='text' /></td>
                     </tr>
                     <tr>
                       <td align='left'><font size='2'>Origin:</font></td>
                       <td align='left'><input name='origin' type='text' /></td>
                     </tr>
                     <tr>
                       <td align='left'><font size='2'>Description:</font></td>
                       <td align='left'><textarea name='description' rows='5' cols='35' /></textarea></td>
                     </tr>
                     <tr>
                       <td align='left'><font size='2'>Visibility</font></td><td align='left'>
                         <select name='visibility' rows='50' />
                         <option value='1'>Visible</option>
                         <option value='0'>Invisible</option>
                         </select>
                       </td>
                     </tr>
                     <tr>
                      <td align='left'><font size='2'>Image 1:</font></td>
                      <td align='left'><input name='img1' type='file' /></td>
                     </tr>
                     <tr>
                       <td align='left'><font size='2'>Image 2:</font></td>
                       <td align='left'><input name='img2' type='file' /></td>
                     </tr>
                  <tr>
                    <td>&nbsp;</td>
                  </tr>
                  <tr>
                    <td align='left'><input name='submit' type='submit' value='Add!!' /></td>
                  </tr>
                  </form>
                </table>
                </div>
            </div></td>
          </tr>
          <tr>
            <td colspan="2">&nbsp;</td>
          </tr>
        </table></th>
<?php
    include_template("admin_footer.php");
?>

エラーが発生しています:

Notice: Undefined index: file_upload in ..\admin\addproduct.php on line 48
Notice: Undefined index: in ..\admin\addproduct.php on line 49

それは次のとおりです。

if(move_uploaded_file($tmp_file, $upload_dir."/".$target_file) && move_uploaded_file($tmp_file1, $upload_dir."/".$target_file1)) {
            $product->create();
            $message = "Product uploaded successfully. <br />";
        } else {
                            echo "<pre>".print_r($_FILES,true)."</pre>";
            $error = $_FILES['file_upload']['error'];
            $message = $upload_errors[$error];
        }

echo "を使用すると

".print_r($_FILES,true)."
"; 私は得る:

配列 ( [img1] => 配列 ( [名前] => IMG_6527.JPG [タイプ] => [tmp_name] => [エラー] => 2 [サイズ] => 0 )

    [img2] => Array
        (
            [name] => 
            [type] => 
            [tmp_name] => 
            [error] => 4
            [size] => 0
        )

)

私を助けてください..

ありがとうございました..

4

2 に答える 2