user2550011
user2550011

Reputation: 13

Photos do not upload

I am using a code!! Here every field in the form uploads except the file (photo) field. Can someone help. I had been using the same code for a while. I have already created the folders needed for the image which is uploads/photos/thumbs Here are the codes!!

<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>

here is the php file

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;
    }
}

Upvotes: 0

Views: 107

Answers (2)

jeroen
jeroen

Reputation: 91762

You need to add an enctype to your form.

Change:

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

to:

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

Upvotes: 1

vaso123
vaso123

Reputation: 12391

Add this to your form tag: enctype="multipart/form-data"

Upvotes: 1

Related Questions