php - Move Uploaded File Function Does Not Move Uploaded Picture -
i'm making online store in php , project have made cms allow admins insert new products store.
here insert_product.php
page:
<?php if(isset($_post['insert_product'])){ // text data variables $product_title = $_post['product_title']; $product_cat = $_post['product_cat']; $product_brand = $_post['product_brand']; $product_price = $_post['product_price']; $product_desc = $_post['product_desc']; $status = 'on'; $product_keywords = $_post['product_keywords']; // image names $product_img1 = $_files['product_img1']['name']; $product_img2 = $_files['product_img2']['name']; $product_img3 = $_files['product_img3']['name']; // image temp names $temp_name1 = $_files['product_img1']['tmp_name']; $temp_name2 = $_files['product_img2']['tmp_name']; $temp_name3 = $_files['product_img3']['tmp_name']; if($product_title == '' or $product_cat == '' or $product_brand == '' or $product_price == '' or $product_desc == '' or $product_keywords == '' or $product_img1 == ''){ echo " <script>alert('please fill fields!')</script> exit(); "; }else{ // uploading images folder move_uploaded_file($temp_name1,"product_images/$product_img1"); move_uploaded_file($temp_name2,"product_images/$product_img2"); move_uploaded_file($temp_name3,"product_images/$product_img3"); $insert_product = " insert products (cat_id,brand_id,date,product_title,product_img1,product_img2,product_img3,product_price,product_desc,status) values ('$product_cat','$product_brand',now(),'$product_title','$product_img1','$product_img2','$product_img3','$product_price','$product_desc','$status') "; $run_product = mysqli_query($con,$insert_product); if($run_product){ echo " <script>alert('product inserted successfully')</script> exit(); "; } } } ?> <div class="content-wrapper"> <section class="content-header"> <h1> add new products <small>onlinestore.danoup.com</small> </h1> <ol class="breadcrumb"> <li class="active">insertproducts.php</li> </ol> </section> <section class="content"> <div class="box box-default"> <div class="box-header with-border"> <h3 class="box-title">overall info</h3> <div class="box-tools pull-right"> <!-- <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button> <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-remove"></i></button> --> </div> </div> <div class="box-body"> <form action="" method="post" enctype="multipart/form-data"> <div class="row"> <div class="col-md-6"> <div class="form-group"> <div class="form-group"> <label>product title:</label> <input type="text" name="product_title" class="form-control my-colorpicker1"> </div> </div> <div class="form-group"> <label>product category:</label> <select class="form-control select2" name="product_cat" style="width: 100%;"> <?php echo get_cats(); ?> </select> </div> <div class="form-group"> <label>product brand:</label> <select class="form-control select2" name="product_brand" style="width: 100%;"> <?php echo get_brands(); ?> </select> </div> <div class="form-group"> <div class="form-group"> <label>product image 1:</label> <input type="file" name="product_img1" class="form-control my-colorpicker1"> </div> </div> <div class="form-group"> <div class="form-group"> <label>product image 2:</label> <input type="file" name="product_img2" class="form-control my-colorpicker1"> </div> </div> <div class="form-group"> <div class="form-group"> <label>product image 3:</label> <input type="file" name="product_img3" class="form-control my-colorpicker1"> </div> </div> </div> <div class="col-md-6"> <div class="form-group"> <div class="form-group"> <label>product price:</label> <input type="text" name="product_price" class="form-control my-colorpicker1"> </div> </div> <div class="form-group"> <div class="form-group"> <label>product keywords:</label> <input type="text" name="product_keywords" class="form-control my-colorpicker1"> </div> </div> <input type="submit" name="insert_product" class="btn" value="submit"> </div> </div> <div class="row"> <div class="col-md-12"> <div class="box box-info"> <div class="box-header"> <h3 class="box-title">product description: <small>add new product onlinestore</small> </h3> <div class="pull-right box-tools"> <button type="button" class="btn btn-info btn-sm" data-widget="collapse" data-toggle="tooltip" title="collapse"> <i class="fa fa-minus"></i></button> <button type="button" class="btn btn-info btn-sm" data-widget="remove" data-toggle="tooltip" title="remove"> <i class="fa fa-times"></i></button> </div> </div> <div class="box-body pad"> <textarea name="product_desc" placeholder="add description product" style="width: 100%; height: 200px; font-size: 14px; line-height: 18px; border: 1px solid #dddddd; padding: 10px;"></textarea> </div> </div> </div> </div> </form> </div> <div class="box-footer"> visit <a href="https://select2.github.io/">select2 documentation</a> more examples , information plugin. </div> </div> </section> </div>
so contains html form , php action file inserting new product , works , problem move_uploaded_file
function not move uploaded image...
and don't see error messages in page. (even when view source-code)
you can try test page on online cms here:
www.danoup.com/admin
so if want follow these instructions access insert_product page:
1- type captcha code
2- insert these user credentials:
username: pouyavey password: godfather123456789
3- when dashboard page, go left menu , click on store , insert new products
4- after can insert new dummy product example make sure fill in fields.
5- when see message, product has been inserted successfully, goto online store site. , right there should able see products not contain uploaded image. this:
so if know error , why thing happens please let me know cause need it...
you need check few things:
- open php ini , check following variable values memory_limit, upload_max_filesize, post_max_size, file_uploads on. ( not uploading file more size mentioned in upload_max_filesize)
- check folder uploading exist or not.
- permission allowed folder in uploading.
- make error_reporting on
- try uploading in try/catch
Comments
Post a Comment