Note that there are some explanatory texts on larger screens.

plurals
  1. POCodeIgniter Image Upload (Insert blank into array)
    primarykey
    data
    text
    <p>The form I'm working with contains info for five people. Optionally, the user can upload a photo for each of the five people. I'm attempting to insert a default image into the resulting array $files where an image is not uploaded. Help would be greatly appreciated.</p> <pre><code>function multiple_upload($upload_dir = APPPATH, $config = array()) { $CI =&amp; get_instance(); $files = array(); if(empty($config)) { $config['upload_path'] = realpath($upload_dir . '/uploads'); $config['allowed_types'] = 'gif|jpg|jpeg|jpe|png'; $config['max_size'] = '2048'; } $CI-&gt;load-&gt;library('upload', $config); $errors = FALSE; $this-&gt;load-&gt;library('image_lib'); // moved outside loop so it'll work foreach($_FILES as $key =&gt; $value) { if( ! empty($value['name'])) { if( ! $CI-&gt;upload-&gt;do_upload($key)) { $data['upload_message'] = $CI-&gt;upload-&gt;display_errors(ERR_OPEN, ERR_CLOSE); // ERR_OPEN and ERR_CLOSE are error delimiters defined in a config file $CI-&gt;load-&gt;vars($data); $errors = TRUE; } else { // resize the saved image $path = $CI-&gt;upload-&gt;data('full_path'); //echo $path['full_path'] . "&lt;Br/&gt;"; $config = array( 'source_image' =&gt; $path['full_path'], 'new_image' =&gt; $upload_dir . 'uploads/thumbs', 'maintain_ration' =&gt; true, 'width' =&gt; 150, 'height' =&gt; 150 ); $this-&gt;image_lib-&gt;initialize($config); $this-&gt;image_lib-&gt;resize(); // Build a file array from all uploaded files $files[] = $CI-&gt;upload-&gt;data(); } } } // There was errors, we have to delete the uploaded files if($errors) { foreach($files as $key =&gt; $file) { @unlink($file['full_path']); } } elseif(empty($files) AND empty($data['upload_message'])) { $CI-&gt;lang-&gt;load('upload'); $data['upload_message'] = ERR_OPEN.$CI-&gt;lang-&gt;line('upload_no_file_selected').ERR_CLOSE; $CI-&gt;load-&gt;vars($data); } else { return $files; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload