简体   繁体   中英

How to show uploaded image on upload_success page - codeigniter

I have an upload page in my codeigniter app and when i upload an image and click submit it redirects to a page called 'upload_success' i want to show the image you just uploaded on that page.

How can i do that?

I used

<script language="javascript"> 
function reload(){window.location.reload();} 
</script>

but then it uploads the image two times.

NOTE: i am using Ci's file uploader class.

Is upload_success also the page that does the upload? because if it is then that is bad architecture because every time user refreshes that page the image will be uploaded again and again.

What you need to do is, on form submit call a script like image_upload which only does the upload then redirects to upload_success which shows message (success/failure) and in that page add an <img> tag which has its src set to the previously uploaded image.

See CI's File Uploading Class .

If going by their controller example, on success this code is executed:

$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);

The image information is in the $data passed to the view, so in the upload_success view, you need to set something like:

<img src="http://mysite.com/path/to/uploads/<?php echo $upload_data['file_name']; ?>" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM