How to upload(and visualization) images without refresh page in php?How can I prevent SQL injection in PHP?How can I upload files asynchronously?How do I give text or an image a transparent background using CSS?How do I modify the URL without reloading the page?How do I get PHP errors to display?How Do You Parse and Process HTML/XML in PHP?Preview an image before it is uploadedHow can I refresh a page with jQuery?Pure JavaScript equivalent of jQuery's $.ready() - how to call a function when the page/DOM is ready for itHow does PHP 'foreach' actually work?

What if a revenant (monster) gains fire resistance?

When were female captains banned from Starfleet?

Picking the different solutions to the time independent Schrodinger eqaution

Mixing PEX brands

Has any country ever had 2 former presidents in jail simultaneously?

Can a stoichiometric mixture of oxygen and methane exist as a liquid at standard pressure and some (low) temperature?

How should I respond when I lied about my education and the company finds out through background check?

Hero deduces identity of a killer

Why is the "ls" command showing permissions of files in a FAT32 partition?

How do you respond to a colleague from another team when they're wrongly expecting that you'll help them?

How can I write humor as character trait?

Why is this estimator biased?

Yosemite Fire Rings - What to Expect?

Do the primes contain an infinite almost arithmetic progression?

Store Credit Card Information in Password Manager?

Why does AES have exactly 10 rounds for a 128-bit key, 12 for 192 bits and 14 for a 256-bit key size?

Can I visit Japan without a visa?

Is there a way to get `mathscr' with lower case letters in pdfLaTeX?

Non-trope happy ending?

Why does a simple loop result in ASYNC_NETWORK_IO waits?

What are some good ways to treat frozen vegetables such that they behave like fresh vegetables when stir frying them?

Keeping a ball lost forever

Need help understanding what a natural log transformation is actually doing and why specific transformations are required for linear regression

What is the highest possible scrabble score for placing a single tile



How to upload(and visualization) images without refresh page in php?


How can I prevent SQL injection in PHP?How can I upload files asynchronously?How do I give text or an image a transparent background using CSS?How do I modify the URL without reloading the page?How do I get PHP errors to display?How Do You Parse and Process HTML/XML in PHP?Preview an image before it is uploadedHow can I refresh a page with jQuery?Pure JavaScript equivalent of jQuery's $.ready() - how to call a function when the page/DOM is ready for itHow does PHP 'foreach' actually work?













0















Could you tell me how i can upload and visualization images without refresh page in php like this picture(for example):



enter image description here



When I click on "+" i can upload the image,and the image is being visualized at the moment(without refresh page).
Here is my php code:



public function create() {
$this->requireSession();
$this->load->model('store_model');

$visible = 0;
if($this->input->post('is_visible') == 'on')
$visible = 1;


$promotion = 0;
if($this->input->post('is_promotion') == 'on')
$promotion = 1;


$internal = 0;
if($this->input->post('is_internal') == 'on')
$internal = 1;


$userId = $this->authorization->getUserId();
$storeId = $this->authorization->getStore();

$price = $this->input->post('price');
$prev_price = $this->input->post('prev_price');
if($promotion == 1)
$price = $this->input->post('prev_price');
$prev_price = $this->input->post('price');


date_default_timezone_set('Europe/Sofia');

$data = array(
'name' => $this->input->post('name'),
'description' => $this->input->post('description'),
'price' => $price,
'currency' => 'BGN',
'is_promotion' => $promotion,
'promotion_price' => $prev_price,
'quantity' => $this->input->post('quantity'),
'status' => $this->input->post('status'),
'main_image' => 0,
'is_internal' => $internal,
'is_visible' => $visible,
'url_address' => $this->input->post('url'),
'total_views' => 0,
'total_likes' => 0,
'total_comments' => 0,
'product_added' => date("Y-m-d H:i:s"),
'is_active' => 1,
'category_id' => $this->input->post('category_id'),
'user_id' => $this->authorization->getUserId(),
'store_id' => $storeId,
'brand_id' => $this->input->post('brand_id')
);

$this->db->insert("products", $data);
$product_id = $this->db->insert_id();

$this->db->query("UPDATE categories SET total_products = total_products + 1 WHERE id = " . $this->input->post('category_id'));
$this->db->query("UPDATE stores SET total_products = total_products + 1 WHERE id = " . $storeId);
$this->db->query("UPDATE users SET total_products = total_products + 1 WHERE id = " . $userId);

$tags = $this->input->post('tags');
$this->load->model('tag_model');
$this->tag_model->updateTags($tags, $product_id);

$this->load->model('category_model');
$this->load->model('attribute_model');
$attributes = $this->category_model->getOnlyAttributes($this->input->post('category_id'));
$values = array();
foreach($attributes as $row)
$values[] = array('product_id' => $product_id, 'attribute_value_id' => $this->input->post('attribute_id' . $row->attribute_id));

if($attributes)
$this->attribute_model->updateProductAttributes($values, $product_id);


if($_FILES["fileToUpload"]["tmp_name"])
$uploadOk = 1;
//$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false)
$uploadOk = 1;
else
$uploadOk = 0;

// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000)
$uploadOk = 0;

// Allow certain file formats
/*if($imageFileType != "jpg")
$uploadOk = 0;
*/
// Check if $uploadOk is set to 1
if ($uploadOk == 1)
$this->db->insert('products_images', array('product_id' => $product_id));
$insert = $this->db->insert_id();

$target_dir = "./" . p_image_path();
$target_file = $target_dir . '/' . $insert . '.jpg';
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);
$this->db->update("products", array('main_image' => $insert), array('id' => $product_id));




redirect(site_url('mystore/products/edit/' . $product_id));


Here is my html code:



<div class="item-card">
<div class="card-section">
<div class="clearfix">
<!---<div class="pull-right">
<input type="file" name="fileToUpload" id="fileToUpload">
</div>---->

<div class="pull-right">
<span class="btn btn-white upload_image" type="file" id="fileToUpload">Upload image</span>
<input class="upload_file" type="file" name="fileToUpload" id="fileToUpload" style="display:none;">
</div>

<h2 class="al">Images</h2>
</div>
<hr />
<div class="item-images clearfix">
<div class="empty-text">
Upload images
</div>
</div>
</div>
</div>


And div class when the images will be show:



<script type="text/template" id="tpl-product-image">
<div class="col-sm-6 col-md-4 item-thumb" data-idx="fileId">
<div class="image-holder thumbnail">
<div class="preview">
<img src="fileUrl" />
</div>
<div class="caption clearfix">
<label class="pull-left">
#is_main
<input type="checkbox" class="uniform check-main" data-idx="fileId" checked />
/is_main
^is_main
<input type="checkbox" class="uniform check-main" data-idx="fileId" />
/is_main
Заглавна
</label>
<button class="remove-image btn btn-white pull-right" data-idx="fileId">
<i class="glyphicon glyphicon-trash"></i>
</button>
</div>
</div>
</div>
</script>


and JQUERY:



$('.upload_image').click(function() 
$(".upload_file").trigger("click");
);









share|improve this question




























    0















    Could you tell me how i can upload and visualization images without refresh page in php like this picture(for example):



    enter image description here



    When I click on "+" i can upload the image,and the image is being visualized at the moment(without refresh page).
    Here is my php code:



    public function create() {
    $this->requireSession();
    $this->load->model('store_model');

    $visible = 0;
    if($this->input->post('is_visible') == 'on')
    $visible = 1;


    $promotion = 0;
    if($this->input->post('is_promotion') == 'on')
    $promotion = 1;


    $internal = 0;
    if($this->input->post('is_internal') == 'on')
    $internal = 1;


    $userId = $this->authorization->getUserId();
    $storeId = $this->authorization->getStore();

    $price = $this->input->post('price');
    $prev_price = $this->input->post('prev_price');
    if($promotion == 1)
    $price = $this->input->post('prev_price');
    $prev_price = $this->input->post('price');


    date_default_timezone_set('Europe/Sofia');

    $data = array(
    'name' => $this->input->post('name'),
    'description' => $this->input->post('description'),
    'price' => $price,
    'currency' => 'BGN',
    'is_promotion' => $promotion,
    'promotion_price' => $prev_price,
    'quantity' => $this->input->post('quantity'),
    'status' => $this->input->post('status'),
    'main_image' => 0,
    'is_internal' => $internal,
    'is_visible' => $visible,
    'url_address' => $this->input->post('url'),
    'total_views' => 0,
    'total_likes' => 0,
    'total_comments' => 0,
    'product_added' => date("Y-m-d H:i:s"),
    'is_active' => 1,
    'category_id' => $this->input->post('category_id'),
    'user_id' => $this->authorization->getUserId(),
    'store_id' => $storeId,
    'brand_id' => $this->input->post('brand_id')
    );

    $this->db->insert("products", $data);
    $product_id = $this->db->insert_id();

    $this->db->query("UPDATE categories SET total_products = total_products + 1 WHERE id = " . $this->input->post('category_id'));
    $this->db->query("UPDATE stores SET total_products = total_products + 1 WHERE id = " . $storeId);
    $this->db->query("UPDATE users SET total_products = total_products + 1 WHERE id = " . $userId);

    $tags = $this->input->post('tags');
    $this->load->model('tag_model');
    $this->tag_model->updateTags($tags, $product_id);

    $this->load->model('category_model');
    $this->load->model('attribute_model');
    $attributes = $this->category_model->getOnlyAttributes($this->input->post('category_id'));
    $values = array();
    foreach($attributes as $row)
    $values[] = array('product_id' => $product_id, 'attribute_value_id' => $this->input->post('attribute_id' . $row->attribute_id));

    if($attributes)
    $this->attribute_model->updateProductAttributes($values, $product_id);


    if($_FILES["fileToUpload"]["tmp_name"])
    $uploadOk = 1;
    //$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
    // Check if image file is a actual image or fake image
    $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
    if($check !== false)
    $uploadOk = 1;
    else
    $uploadOk = 0;

    // Check file size
    if ($_FILES["fileToUpload"]["size"] > 500000)
    $uploadOk = 0;

    // Allow certain file formats
    /*if($imageFileType != "jpg")
    $uploadOk = 0;
    */
    // Check if $uploadOk is set to 1
    if ($uploadOk == 1)
    $this->db->insert('products_images', array('product_id' => $product_id));
    $insert = $this->db->insert_id();

    $target_dir = "./" . p_image_path();
    $target_file = $target_dir . '/' . $insert . '.jpg';
    move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);
    $this->db->update("products", array('main_image' => $insert), array('id' => $product_id));




    redirect(site_url('mystore/products/edit/' . $product_id));


    Here is my html code:



    <div class="item-card">
    <div class="card-section">
    <div class="clearfix">
    <!---<div class="pull-right">
    <input type="file" name="fileToUpload" id="fileToUpload">
    </div>---->

    <div class="pull-right">
    <span class="btn btn-white upload_image" type="file" id="fileToUpload">Upload image</span>
    <input class="upload_file" type="file" name="fileToUpload" id="fileToUpload" style="display:none;">
    </div>

    <h2 class="al">Images</h2>
    </div>
    <hr />
    <div class="item-images clearfix">
    <div class="empty-text">
    Upload images
    </div>
    </div>
    </div>
    </div>


    And div class when the images will be show:



    <script type="text/template" id="tpl-product-image">
    <div class="col-sm-6 col-md-4 item-thumb" data-idx="fileId">
    <div class="image-holder thumbnail">
    <div class="preview">
    <img src="fileUrl" />
    </div>
    <div class="caption clearfix">
    <label class="pull-left">
    #is_main
    <input type="checkbox" class="uniform check-main" data-idx="fileId" checked />
    /is_main
    ^is_main
    <input type="checkbox" class="uniform check-main" data-idx="fileId" />
    /is_main
    Заглавна
    </label>
    <button class="remove-image btn btn-white pull-right" data-idx="fileId">
    <i class="glyphicon glyphicon-trash"></i>
    </button>
    </div>
    </div>
    </div>
    </script>


    and JQUERY:



    $('.upload_image').click(function() 
    $(".upload_file").trigger("click");
    );









    share|improve this question


























      0












      0








      0








      Could you tell me how i can upload and visualization images without refresh page in php like this picture(for example):



      enter image description here



      When I click on "+" i can upload the image,and the image is being visualized at the moment(without refresh page).
      Here is my php code:



      public function create() {
      $this->requireSession();
      $this->load->model('store_model');

      $visible = 0;
      if($this->input->post('is_visible') == 'on')
      $visible = 1;


      $promotion = 0;
      if($this->input->post('is_promotion') == 'on')
      $promotion = 1;


      $internal = 0;
      if($this->input->post('is_internal') == 'on')
      $internal = 1;


      $userId = $this->authorization->getUserId();
      $storeId = $this->authorization->getStore();

      $price = $this->input->post('price');
      $prev_price = $this->input->post('prev_price');
      if($promotion == 1)
      $price = $this->input->post('prev_price');
      $prev_price = $this->input->post('price');


      date_default_timezone_set('Europe/Sofia');

      $data = array(
      'name' => $this->input->post('name'),
      'description' => $this->input->post('description'),
      'price' => $price,
      'currency' => 'BGN',
      'is_promotion' => $promotion,
      'promotion_price' => $prev_price,
      'quantity' => $this->input->post('quantity'),
      'status' => $this->input->post('status'),
      'main_image' => 0,
      'is_internal' => $internal,
      'is_visible' => $visible,
      'url_address' => $this->input->post('url'),
      'total_views' => 0,
      'total_likes' => 0,
      'total_comments' => 0,
      'product_added' => date("Y-m-d H:i:s"),
      'is_active' => 1,
      'category_id' => $this->input->post('category_id'),
      'user_id' => $this->authorization->getUserId(),
      'store_id' => $storeId,
      'brand_id' => $this->input->post('brand_id')
      );

      $this->db->insert("products", $data);
      $product_id = $this->db->insert_id();

      $this->db->query("UPDATE categories SET total_products = total_products + 1 WHERE id = " . $this->input->post('category_id'));
      $this->db->query("UPDATE stores SET total_products = total_products + 1 WHERE id = " . $storeId);
      $this->db->query("UPDATE users SET total_products = total_products + 1 WHERE id = " . $userId);

      $tags = $this->input->post('tags');
      $this->load->model('tag_model');
      $this->tag_model->updateTags($tags, $product_id);

      $this->load->model('category_model');
      $this->load->model('attribute_model');
      $attributes = $this->category_model->getOnlyAttributes($this->input->post('category_id'));
      $values = array();
      foreach($attributes as $row)
      $values[] = array('product_id' => $product_id, 'attribute_value_id' => $this->input->post('attribute_id' . $row->attribute_id));

      if($attributes)
      $this->attribute_model->updateProductAttributes($values, $product_id);


      if($_FILES["fileToUpload"]["tmp_name"])
      $uploadOk = 1;
      //$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
      // Check if image file is a actual image or fake image
      $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
      if($check !== false)
      $uploadOk = 1;
      else
      $uploadOk = 0;

      // Check file size
      if ($_FILES["fileToUpload"]["size"] > 500000)
      $uploadOk = 0;

      // Allow certain file formats
      /*if($imageFileType != "jpg")
      $uploadOk = 0;
      */
      // Check if $uploadOk is set to 1
      if ($uploadOk == 1)
      $this->db->insert('products_images', array('product_id' => $product_id));
      $insert = $this->db->insert_id();

      $target_dir = "./" . p_image_path();
      $target_file = $target_dir . '/' . $insert . '.jpg';
      move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);
      $this->db->update("products", array('main_image' => $insert), array('id' => $product_id));




      redirect(site_url('mystore/products/edit/' . $product_id));


      Here is my html code:



      <div class="item-card">
      <div class="card-section">
      <div class="clearfix">
      <!---<div class="pull-right">
      <input type="file" name="fileToUpload" id="fileToUpload">
      </div>---->

      <div class="pull-right">
      <span class="btn btn-white upload_image" type="file" id="fileToUpload">Upload image</span>
      <input class="upload_file" type="file" name="fileToUpload" id="fileToUpload" style="display:none;">
      </div>

      <h2 class="al">Images</h2>
      </div>
      <hr />
      <div class="item-images clearfix">
      <div class="empty-text">
      Upload images
      </div>
      </div>
      </div>
      </div>


      And div class when the images will be show:



      <script type="text/template" id="tpl-product-image">
      <div class="col-sm-6 col-md-4 item-thumb" data-idx="fileId">
      <div class="image-holder thumbnail">
      <div class="preview">
      <img src="fileUrl" />
      </div>
      <div class="caption clearfix">
      <label class="pull-left">
      #is_main
      <input type="checkbox" class="uniform check-main" data-idx="fileId" checked />
      /is_main
      ^is_main
      <input type="checkbox" class="uniform check-main" data-idx="fileId" />
      /is_main
      Заглавна
      </label>
      <button class="remove-image btn btn-white pull-right" data-idx="fileId">
      <i class="glyphicon glyphicon-trash"></i>
      </button>
      </div>
      </div>
      </div>
      </script>


      and JQUERY:



      $('.upload_image').click(function() 
      $(".upload_file").trigger("click");
      );









      share|improve this question
















      Could you tell me how i can upload and visualization images without refresh page in php like this picture(for example):



      enter image description here



      When I click on "+" i can upload the image,and the image is being visualized at the moment(without refresh page).
      Here is my php code:



      public function create() {
      $this->requireSession();
      $this->load->model('store_model');

      $visible = 0;
      if($this->input->post('is_visible') == 'on')
      $visible = 1;


      $promotion = 0;
      if($this->input->post('is_promotion') == 'on')
      $promotion = 1;


      $internal = 0;
      if($this->input->post('is_internal') == 'on')
      $internal = 1;


      $userId = $this->authorization->getUserId();
      $storeId = $this->authorization->getStore();

      $price = $this->input->post('price');
      $prev_price = $this->input->post('prev_price');
      if($promotion == 1)
      $price = $this->input->post('prev_price');
      $prev_price = $this->input->post('price');


      date_default_timezone_set('Europe/Sofia');

      $data = array(
      'name' => $this->input->post('name'),
      'description' => $this->input->post('description'),
      'price' => $price,
      'currency' => 'BGN',
      'is_promotion' => $promotion,
      'promotion_price' => $prev_price,
      'quantity' => $this->input->post('quantity'),
      'status' => $this->input->post('status'),
      'main_image' => 0,
      'is_internal' => $internal,
      'is_visible' => $visible,
      'url_address' => $this->input->post('url'),
      'total_views' => 0,
      'total_likes' => 0,
      'total_comments' => 0,
      'product_added' => date("Y-m-d H:i:s"),
      'is_active' => 1,
      'category_id' => $this->input->post('category_id'),
      'user_id' => $this->authorization->getUserId(),
      'store_id' => $storeId,
      'brand_id' => $this->input->post('brand_id')
      );

      $this->db->insert("products", $data);
      $product_id = $this->db->insert_id();

      $this->db->query("UPDATE categories SET total_products = total_products + 1 WHERE id = " . $this->input->post('category_id'));
      $this->db->query("UPDATE stores SET total_products = total_products + 1 WHERE id = " . $storeId);
      $this->db->query("UPDATE users SET total_products = total_products + 1 WHERE id = " . $userId);

      $tags = $this->input->post('tags');
      $this->load->model('tag_model');
      $this->tag_model->updateTags($tags, $product_id);

      $this->load->model('category_model');
      $this->load->model('attribute_model');
      $attributes = $this->category_model->getOnlyAttributes($this->input->post('category_id'));
      $values = array();
      foreach($attributes as $row)
      $values[] = array('product_id' => $product_id, 'attribute_value_id' => $this->input->post('attribute_id' . $row->attribute_id));

      if($attributes)
      $this->attribute_model->updateProductAttributes($values, $product_id);


      if($_FILES["fileToUpload"]["tmp_name"])
      $uploadOk = 1;
      //$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
      // Check if image file is a actual image or fake image
      $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
      if($check !== false)
      $uploadOk = 1;
      else
      $uploadOk = 0;

      // Check file size
      if ($_FILES["fileToUpload"]["size"] > 500000)
      $uploadOk = 0;

      // Allow certain file formats
      /*if($imageFileType != "jpg")
      $uploadOk = 0;
      */
      // Check if $uploadOk is set to 1
      if ($uploadOk == 1)
      $this->db->insert('products_images', array('product_id' => $product_id));
      $insert = $this->db->insert_id();

      $target_dir = "./" . p_image_path();
      $target_file = $target_dir . '/' . $insert . '.jpg';
      move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);
      $this->db->update("products", array('main_image' => $insert), array('id' => $product_id));




      redirect(site_url('mystore/products/edit/' . $product_id));


      Here is my html code:



      <div class="item-card">
      <div class="card-section">
      <div class="clearfix">
      <!---<div class="pull-right">
      <input type="file" name="fileToUpload" id="fileToUpload">
      </div>---->

      <div class="pull-right">
      <span class="btn btn-white upload_image" type="file" id="fileToUpload">Upload image</span>
      <input class="upload_file" type="file" name="fileToUpload" id="fileToUpload" style="display:none;">
      </div>

      <h2 class="al">Images</h2>
      </div>
      <hr />
      <div class="item-images clearfix">
      <div class="empty-text">
      Upload images
      </div>
      </div>
      </div>
      </div>


      And div class when the images will be show:



      <script type="text/template" id="tpl-product-image">
      <div class="col-sm-6 col-md-4 item-thumb" data-idx="fileId">
      <div class="image-holder thumbnail">
      <div class="preview">
      <img src="fileUrl" />
      </div>
      <div class="caption clearfix">
      <label class="pull-left">
      #is_main
      <input type="checkbox" class="uniform check-main" data-idx="fileId" checked />
      /is_main
      ^is_main
      <input type="checkbox" class="uniform check-main" data-idx="fileId" />
      /is_main
      Заглавна
      </label>
      <button class="remove-image btn btn-white pull-right" data-idx="fileId">
      <i class="glyphicon glyphicon-trash"></i>
      </button>
      </div>
      </div>
      </div>
      </script>


      and JQUERY:



      $('.upload_image').click(function() 
      $(".upload_file").trigger("click");
      );






      javascript php jquery html upload






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 7 at 7:03







      PetrovD

















      asked Mar 7 at 6:35









      PetrovDPetrovD

      65




      65






















          2 Answers
          2






          active

          oldest

          votes


















          1














          The key to this is using the AJAX feature in the jquery library



          Download the scripts given below from jquery site.







          Use the AjaxUpload function.
          Follow this tutorial for further details : https://css-tricks.com/ajax-image-uploading/






          share|improve this answer






























            1














            use change event, then get the file and send to PHP file
            like below



             $('#fileToUpload').on("change", function () 
            var file = $("#fileToUpload").prop("files")[0];
            var data = new FormData();
            data.append('fileName', file);
            );
            $.ajax(
            url: "urlPHPFILE",
            type: "POST",
            data: data,
            dataType : 'json',
            processData: false,
            contentType: false,
            cache: false,
            success:function(data)

            ,
            error:function(err)
            console.error(err);

            );


            php file



            $file = $_POST['fileName']


            after upload, if you want to do something you must use the success function



            in PHP file you must back Url patch image .and get in on success function.



            PHP file



            .
            .//If the file was successfully uploaded
            $status = array('status' => "success", "urlPatchImage" => $UrlPatch);
            return $status;
            .
            .
            .


            jquery code



            .
            success:function(data)
            var urlPatchImage = data.urlPatchImage;
            $("#image").attr("src", urlPatchImage );
            ,
            .
            .


            html



            <img id="image" src="">





            share|improve this answer

























            • I put this code under my HTML file, but it not works.

              – PetrovD
              Mar 7 at 7:01











            • <input class="upload_file" type="file" name="fileToUpload" id="fileToUpload" style="display:none;"> is that your input ...why it is display:none; ?What error do you get?

              – pedram shabani
              Mar 7 at 7:09











            • Because when I remove "display:none" I see this: imgur.com/CciQmOp

              – PetrovD
              Mar 7 at 7:15











            • My code work, but images are displayed when i click on submit button(after refreshing page)

              – PetrovD
              Mar 7 at 7:16











            • so your problem is not about upload image?

              – pedram shabani
              Mar 7 at 7:24










            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55037474%2fhow-to-uploadand-visualization-images-without-refresh-page-in-php%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            The key to this is using the AJAX feature in the jquery library



            Download the scripts given below from jquery site.







            Use the AjaxUpload function.
            Follow this tutorial for further details : https://css-tricks.com/ajax-image-uploading/






            share|improve this answer



























              1














              The key to this is using the AJAX feature in the jquery library



              Download the scripts given below from jquery site.







              Use the AjaxUpload function.
              Follow this tutorial for further details : https://css-tricks.com/ajax-image-uploading/






              share|improve this answer

























                1












                1








                1







                The key to this is using the AJAX feature in the jquery library



                Download the scripts given below from jquery site.







                Use the AjaxUpload function.
                Follow this tutorial for further details : https://css-tricks.com/ajax-image-uploading/






                share|improve this answer













                The key to this is using the AJAX feature in the jquery library



                Download the scripts given below from jquery site.







                Use the AjaxUpload function.
                Follow this tutorial for further details : https://css-tricks.com/ajax-image-uploading/







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 7 at 6:53









                Magnus MelwinMagnus Melwin

                67411021




                67411021























                    1














                    use change event, then get the file and send to PHP file
                    like below



                     $('#fileToUpload').on("change", function () 
                    var file = $("#fileToUpload").prop("files")[0];
                    var data = new FormData();
                    data.append('fileName', file);
                    );
                    $.ajax(
                    url: "urlPHPFILE",
                    type: "POST",
                    data: data,
                    dataType : 'json',
                    processData: false,
                    contentType: false,
                    cache: false,
                    success:function(data)

                    ,
                    error:function(err)
                    console.error(err);

                    );


                    php file



                    $file = $_POST['fileName']


                    after upload, if you want to do something you must use the success function



                    in PHP file you must back Url patch image .and get in on success function.



                    PHP file



                    .
                    .//If the file was successfully uploaded
                    $status = array('status' => "success", "urlPatchImage" => $UrlPatch);
                    return $status;
                    .
                    .
                    .


                    jquery code



                    .
                    success:function(data)
                    var urlPatchImage = data.urlPatchImage;
                    $("#image").attr("src", urlPatchImage );
                    ,
                    .
                    .


                    html



                    <img id="image" src="">





                    share|improve this answer

























                    • I put this code under my HTML file, but it not works.

                      – PetrovD
                      Mar 7 at 7:01











                    • <input class="upload_file" type="file" name="fileToUpload" id="fileToUpload" style="display:none;"> is that your input ...why it is display:none; ?What error do you get?

                      – pedram shabani
                      Mar 7 at 7:09











                    • Because when I remove "display:none" I see this: imgur.com/CciQmOp

                      – PetrovD
                      Mar 7 at 7:15











                    • My code work, but images are displayed when i click on submit button(after refreshing page)

                      – PetrovD
                      Mar 7 at 7:16











                    • so your problem is not about upload image?

                      – pedram shabani
                      Mar 7 at 7:24















                    1














                    use change event, then get the file and send to PHP file
                    like below



                     $('#fileToUpload').on("change", function () 
                    var file = $("#fileToUpload").prop("files")[0];
                    var data = new FormData();
                    data.append('fileName', file);
                    );
                    $.ajax(
                    url: "urlPHPFILE",
                    type: "POST",
                    data: data,
                    dataType : 'json',
                    processData: false,
                    contentType: false,
                    cache: false,
                    success:function(data)

                    ,
                    error:function(err)
                    console.error(err);

                    );


                    php file



                    $file = $_POST['fileName']


                    after upload, if you want to do something you must use the success function



                    in PHP file you must back Url patch image .and get in on success function.



                    PHP file



                    .
                    .//If the file was successfully uploaded
                    $status = array('status' => "success", "urlPatchImage" => $UrlPatch);
                    return $status;
                    .
                    .
                    .


                    jquery code



                    .
                    success:function(data)
                    var urlPatchImage = data.urlPatchImage;
                    $("#image").attr("src", urlPatchImage );
                    ,
                    .
                    .


                    html



                    <img id="image" src="">





                    share|improve this answer

























                    • I put this code under my HTML file, but it not works.

                      – PetrovD
                      Mar 7 at 7:01











                    • <input class="upload_file" type="file" name="fileToUpload" id="fileToUpload" style="display:none;"> is that your input ...why it is display:none; ?What error do you get?

                      – pedram shabani
                      Mar 7 at 7:09











                    • Because when I remove "display:none" I see this: imgur.com/CciQmOp

                      – PetrovD
                      Mar 7 at 7:15











                    • My code work, but images are displayed when i click on submit button(after refreshing page)

                      – PetrovD
                      Mar 7 at 7:16











                    • so your problem is not about upload image?

                      – pedram shabani
                      Mar 7 at 7:24













                    1












                    1








                    1







                    use change event, then get the file and send to PHP file
                    like below



                     $('#fileToUpload').on("change", function () 
                    var file = $("#fileToUpload").prop("files")[0];
                    var data = new FormData();
                    data.append('fileName', file);
                    );
                    $.ajax(
                    url: "urlPHPFILE",
                    type: "POST",
                    data: data,
                    dataType : 'json',
                    processData: false,
                    contentType: false,
                    cache: false,
                    success:function(data)

                    ,
                    error:function(err)
                    console.error(err);

                    );


                    php file



                    $file = $_POST['fileName']


                    after upload, if you want to do something you must use the success function



                    in PHP file you must back Url patch image .and get in on success function.



                    PHP file



                    .
                    .//If the file was successfully uploaded
                    $status = array('status' => "success", "urlPatchImage" => $UrlPatch);
                    return $status;
                    .
                    .
                    .


                    jquery code



                    .
                    success:function(data)
                    var urlPatchImage = data.urlPatchImage;
                    $("#image").attr("src", urlPatchImage );
                    ,
                    .
                    .


                    html



                    <img id="image" src="">





                    share|improve this answer















                    use change event, then get the file and send to PHP file
                    like below



                     $('#fileToUpload').on("change", function () 
                    var file = $("#fileToUpload").prop("files")[0];
                    var data = new FormData();
                    data.append('fileName', file);
                    );
                    $.ajax(
                    url: "urlPHPFILE",
                    type: "POST",
                    data: data,
                    dataType : 'json',
                    processData: false,
                    contentType: false,
                    cache: false,
                    success:function(data)

                    ,
                    error:function(err)
                    console.error(err);

                    );


                    php file



                    $file = $_POST['fileName']


                    after upload, if you want to do something you must use the success function



                    in PHP file you must back Url patch image .and get in on success function.



                    PHP file



                    .
                    .//If the file was successfully uploaded
                    $status = array('status' => "success", "urlPatchImage" => $UrlPatch);
                    return $status;
                    .
                    .
                    .


                    jquery code



                    .
                    success:function(data)
                    var urlPatchImage = data.urlPatchImage;
                    $("#image").attr("src", urlPatchImage );
                    ,
                    .
                    .


                    html



                    <img id="image" src="">






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Mar 7 at 8:09

























                    answered Mar 7 at 6:52









                    pedram shabanipedram shabani

                    1,1042822




                    1,1042822












                    • I put this code under my HTML file, but it not works.

                      – PetrovD
                      Mar 7 at 7:01











                    • <input class="upload_file" type="file" name="fileToUpload" id="fileToUpload" style="display:none;"> is that your input ...why it is display:none; ?What error do you get?

                      – pedram shabani
                      Mar 7 at 7:09











                    • Because when I remove "display:none" I see this: imgur.com/CciQmOp

                      – PetrovD
                      Mar 7 at 7:15











                    • My code work, but images are displayed when i click on submit button(after refreshing page)

                      – PetrovD
                      Mar 7 at 7:16











                    • so your problem is not about upload image?

                      – pedram shabani
                      Mar 7 at 7:24

















                    • I put this code under my HTML file, but it not works.

                      – PetrovD
                      Mar 7 at 7:01











                    • <input class="upload_file" type="file" name="fileToUpload" id="fileToUpload" style="display:none;"> is that your input ...why it is display:none; ?What error do you get?

                      – pedram shabani
                      Mar 7 at 7:09











                    • Because when I remove "display:none" I see this: imgur.com/CciQmOp

                      – PetrovD
                      Mar 7 at 7:15











                    • My code work, but images are displayed when i click on submit button(after refreshing page)

                      – PetrovD
                      Mar 7 at 7:16











                    • so your problem is not about upload image?

                      – pedram shabani
                      Mar 7 at 7:24
















                    I put this code under my HTML file, but it not works.

                    – PetrovD
                    Mar 7 at 7:01





                    I put this code under my HTML file, but it not works.

                    – PetrovD
                    Mar 7 at 7:01













                    <input class="upload_file" type="file" name="fileToUpload" id="fileToUpload" style="display:none;"> is that your input ...why it is display:none; ?What error do you get?

                    – pedram shabani
                    Mar 7 at 7:09





                    <input class="upload_file" type="file" name="fileToUpload" id="fileToUpload" style="display:none;"> is that your input ...why it is display:none; ?What error do you get?

                    – pedram shabani
                    Mar 7 at 7:09













                    Because when I remove "display:none" I see this: imgur.com/CciQmOp

                    – PetrovD
                    Mar 7 at 7:15





                    Because when I remove "display:none" I see this: imgur.com/CciQmOp

                    – PetrovD
                    Mar 7 at 7:15













                    My code work, but images are displayed when i click on submit button(after refreshing page)

                    – PetrovD
                    Mar 7 at 7:16





                    My code work, but images are displayed when i click on submit button(after refreshing page)

                    – PetrovD
                    Mar 7 at 7:16













                    so your problem is not about upload image?

                    – pedram shabani
                    Mar 7 at 7:24





                    so your problem is not about upload image?

                    – pedram shabani
                    Mar 7 at 7:24

















                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55037474%2fhow-to-uploadand-visualization-images-without-refresh-page-in-php%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    1928 у кіно

                    Захаров Федір Захарович

                    Ель Греко