0

私は次のようなhtmlコードを持っています: -

<form id="form" name="form" action="banner_ad_post.php" method="post" enctype="multipart/form-data">
                <p>
                  <label for="banner_name"><font color="#FF0000"> * </font>Banner Name: </label>
                  <input type="text" name="banner_name" id="banner_name" value="" maxlength="100" required="required"/>
                </p>
                <p>
                  <label for="Banner_website_url"><font color="#FF0000"> * </font>Banner website Url: </label>
                  <input type="url" name="banner_site_url" id="banner_site_url" value="" maxlength="100" required="required"/>
                </p>

                <p>
                  <label for="banner_image_url">Banner Image Url: </label>
                  <input type="file" name="file" id="file" value="" accept="image" placeholder="Browse from hard disk" onchange="img_path()"/> &nbsp;
                   <font color="#FF0000"> OR</font> &nbsp;
                  <input type="url" name="banner_image_url" id="banner_image_url" value="" maxlength="100" placeholder="Enter the url from website." onchange="validate()"/> &nbsp; 


                </p>
                <p>
                <label for="submit"> </label>
                  <input type="submit" id="submit" name="submit" value="Submit" onclick="preview()" />
                </p>
              </form>

そして次のようなphpスクリプト: -

<?php 
     if(isset($_POST['banner_name']) && isset($_POST['banner_site_url']) && isset($_POST['banner_image_url']) && isset($_FILES['file']['name']))
     {
        $banner_name=$_POST['banner_name'];
        $banner_name=strip_tags($banner_name);
        $banner_site_url=$_POST['banner_site_url'];
        $banner_site_url=strip_tags($banner_site_url);
        $banner_image_url=$_POST['banner_image_url'];
        $banner_image_url=strip_tags($banner_image_url);
        $name=$_FILES['file']['name'];

        $size=$_FILES['file']['size'];
        $type=$_FILES['file']['type'];
        $tmp_name=$_FILES['file']['tmp_name'];
        $error=$_FILES['file']['error'];
        $maxsize = 512000;
        $location='uploads/';
        if(!empty($banner_image_url))
            {
            $file_location=$banner_image_url;
            ?>
            <div id="img"> 
            <img src="<?php echo $file_location?>" align="left" width="200px" height="200px">
            </div>
            <?php
            } elseif (!empty($name))
            {
            $file_location=$location.$name;
            ?>
                    <div id="img">  
                    <img src="http://localhost/leadstool/<?php echo $file_location?>" align="left" width="200px" height="200px">
                    </div>

                    <?php 
            }

          if(!empty($banner_name) && !empty($banner_site_url))
          {
             $query="INSERT INTO `banner_ad` VALUES('','$id','$banner_name','$file_location','$banner_site_url','0',now())";
             if($query_run=mysql_query($query))
             {
                if($size <= $maxsize)
                {                         
                  if(move_uploaded_file($tmp_name,$location.$name))
                    {
                    echo'<font color="green">File uploaded & has been sent for approval.</font>';
                    } 
                    else 
                    {
                    echo'<font color="red">File can not be uploaded.</font>';

                    }
                } else {
                echo'<font color="green">Your information has been uploaded and has been sent for approval.</font>';
                }
             }
             else
             {
                  echo'<font color="red"> The request can not be performed.</font>';
             }
         } 
         else 
         {
          echo'<font color="red">These fields are mandatory.</font>';
         }
    }

     ?>

ここでの問題は、何らかの理由で move_uploaded_file() メソッドがデータベースにファイルをアップロードできないことが原因です。しかし、それでも「ファイルがアップロードされ、承認のために送信されました」のような出力が得られます。さて、ここで何が欠けているのか正確にはわかりませんか?

どんな助けでも大歓迎です... よろしくお願いします!

4

2 に答える 2

1

ごめん!この質問にはプログラミングエラーはありません。単純な論理エラー。

問題を修正するために編集したコードを再投稿しています。

if($size <= $maxsize)
                {                         
                  if(move_uploaded_file($tmp_name,$location.$name))
                    {
                    echo'<font color="green">File uploaded & has been sent for approval.</font>';
                    } 
                    else 
                    {
                    echo'<font color="red">File can not be uploaded.</font>';
                    ?>
                    <div id="img">  
                    <img src="http://localhost/leadstool/<?php echo $file_location?>" align="left" width="200px" height="200px">
                    </div>

                    <?php 

                    }
                } else {
                echo'<font color="red">File size must be less than 500KB.</font>';
                }
于 2012-11-24T22:14:32.503 に答える