Note that there are some explanatory texts on larger screens.

plurals
  1. POGet Renamed File Names of JavaScript Forms in CodeIgniter
    primarykey
    data
    text
    <p>I have a multiple image upload form, and the following code is working well for uploading. I need to save file names to database to the database, but I cannot figure out how to do that properly.</p> <p><strong><code>uploadform.php</code></strong>:</p> <pre><code> echo form_open_multipart('gallery/upload'); &lt;input type="file" name="photo" size="50" /&gt; &lt;input type="file" name="thumb" size="50" /&gt; &lt;input type="submit" value="Upload" /&gt; &lt;/form&gt; </code></pre> <p><strong><code>gallery_model.php</code></strong></p> <pre><code> function multiple_upload($upload_dir = 'uploads/', $config = array()) { /* Upload */ $CI =&amp; get_instance(); $files = array(); if(empty($config)) { $config['upload_path'] = realpath($upload_dir); $config['allowed_types'] = 'gif|jpg|jpeg|jpe|png'; $config['max_size'] = '2048'; } $CI-&gt;load-&gt;library('upload', $config); $errors = FALSE; 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 { // 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; } /* ------------------------------- Insert to database */ // problem is here, i need file names to add db. // if there is already same names file at the folder, it rename file itself. so in such case, I need renamed file name :/ } } </code></pre>
    singulars
    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.
 

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