照片不上传

时间:2014-10-30 16:08:38

标签: php html sql

我正在使用代码!除了文件(照片)字段之外,表单中的每个字段都会上传。有人可以帮忙吗我一直在使用相同的代码。我已经创建了图像所需的文件夹,上传/照片/拇指以下是代码!!

<article class="col-md-8 body-box box-form">
        <div class="body-form">
            <h2 class="text-danger"> Upload Photos<h2>
                    <?php if(isset($photo->sysMessage)) { echo $photo->sysMessage; } ?>
            <div class="col-md-8">
                <form role="form" action="" method="post">

                  <div class="form-group">
                    <label>Category</label> 
                   <select name="pht_pho_ID" class="form-control">
                                    <option></option>
                                    <?php $photo->optionCategories(); ?>
                                </select>
                  </div>

                        <!-- Javascript --> 
                        <script>
                            init.push(function () {
                                $('#styled-finputs').pixelFileInput({ placeholder: 'No file selected...' });
                            })
                        </script> 
                        <!-- / Javascript -->
                        <div class="form-group">
                    <label>Photo</label>
                    <input type="file"  name="pht_image" />
                  </div>
                  <div class="form-group">
                    <label>Title</label>
                    <input type="text" id="styled-finputs" name="pht_title">
                  </div>

                  <div class="form-group">
                    <label>Publish </label>
                    <input type="radio" class="form-control" value="1" name="pht_published">
                    Yes
                  </div>
                <div class="form-group">

                    <input type="radio" class="form-control" value="0" name="pht_published">
                    No
                  </div>

                  <button type="submit" class="btn btn-danger" name="save">Submit</button>

                </form> 
            </div><!-- end of col-md-6 -->



        </div>
    </article>

这是php文件

function add() {
    // escape();        
    require_once('imageUpload.php');
    $imageUpload = new imageUpload();
    $upload = $imageUpload->uploadImageThumb($_FILES['pht_image']['name'], $_FILES['pht_image']['tmp_name'], 'uploads/photos/', 300, 300);
    if($upload == 1) {
        $qry = "INSERT INTO photos (pht_title, pht_pho_ID, pht_image, pht_published) VALUES ('$_POST[pht_title]', $_POST[pht_pho_ID], '$imageUpload->filename', $_POST[pht_published])";
        if(mysql_query($qry)) {
            $pht_ID = mysql_insert_id();
            header( 'Location: photos-edit.php?arg=addSuccess&pht_ID='.$pht_ID ) ;
        }
        else {
            echo mysql_error();
        }
    }
    else {
        echo $upload;
    }
}

2 个答案:

答案 0 :(得分:1)

将此添加到您的表单标记:enctype="multipart/form-data"

答案 1 :(得分:1)

您需要在表单中添加enctype

变化:

<form role="form" action="" method="post">

为:

<form role="form" action="" method="post" enctype="multipart/form-data">