How to upload multiple files using smarty in php? -
i make select box in select different resumes apply on same job when applying jobs gives me error "you applied"
here apply_now.tpl:
{literal} <script> function applysubmit() { $("#applicationform").hide(); $("#progressbar").show(); $("#applyform").ajaxsubmit({ url: $("#applyform").attr("action"), type: "post", success: function (data) { $("#messagebox").html(data); } }); return false; } $(document).ready(function() { $("#applyform").jqtransform(); }); </script> {/literal} div id="progressbar" style="display:none"><img src="{$globals.site_url}/system/ext/jquery/progbar.gif" alt="[[please wait ...]]" />[[please wait ...]]</div> <div id="applicationform"> {if $is_data_submitted && !$errors} <p class="message">[[you applied successfully]]</p> {else} {foreach from=$errors key=error_code item=error_message} <p class="error"> {if $error_code eq 'empty_value'} [[enter security code]] {elseif $error_code eq 'not_valid'} [[security code not valid]] {elseif $error_code eq 'send_error'} [[there error while sending application.]] {else}[[{$error_message}]] {/if} </p> {/foreach} {include file='field_errors.tpl'} <form method="post" enctype="multipart/form-data" action="{$globals.site_url}/apply-now/" id="applyform"> <input type="hidden" name="is_data_submitted" value="1"> <input type="hidden" name="listing_id" value="{$listing_id}"> {if not $globals.current_user.logged_in} <fieldset> <div class="inputname">[[your name]]:</div> <div class="inputfield"><input type="text" name="name" value="{$request.name}" /></div> </fieldset> <fieldset> <div class="inputname">[[your e-mail]]:</div> <div class="inputfield"><input type="text" name="email" value="{$request.email}" /></div> </fieldset> {/if} <fieldset> <div class="inputname">[[cover letter (optional)]]:</div> <div class="inputfield"><textarea name="comments" rows="5">{$request.comments}</textarea></div> </fieldset> {if $globals.current_user.logged_in && $resume} <fieldset> <div class="inputname">[[select resume]]:</div> <div class="inputfield"> <select name="id_resume" multiple="multiple"> <option value="0" selected="selected">[[select resume]]</option> {html_options options=$resume selected=$request.id_resume} </select> <br />or </div> </fieldset> {/if} <fieldset> <div class="inputname">[[attach resume]]:</div> <div class="inputfield"><input type="file" name="file_tmp" /></div> </fieldset> {if $iscaptcha == 1} <fieldset> <div class="inputname">[[$captcha.caption]]:</div> <div class="inputfield">{input property=$captcha.id object=$captchaobject}</div> </fieldset> {/if} <input type="hidden" name="anonymous" value="1" /> {if $form_fields} <fieldset> {include file="questionnaire.tpl" form_fields=$form_fields} </fieldset> {/if} <fieldset> <div class="inputname"> </div> <div class="inputbutton"><input id="submitbutton" type="submit" value="[[send]]" onclick="return applysubmit();"/></div> </fieldset> </form> {/if} </div> and here apply_now.php code:
$listingid = 0; $post['submitted_data']['questionnaire'] = ''; if (isset($post['submitted_data']['id_resume'])) $listingid = $post['submitted_data']['id_resume']; $mimetype = isset($_files['file_tmp']['type']) ? $_files['file_tmp']['type'] : ''; if (isset($_files['file_tmp']['size']) && $file_name != '' && $_files['file_tmp']['size'] == 0) { $errors['file_is_empty'] = 'the uploaded file should not blank'; } if (!empty($_files['file_tmp']['name'])){ $fileformats = explode(',',sjb_system::getsettingbyname('file_valid_types')); $fileinfo = pathinfo($_files['file_tmp']['name']); if (!in_array(strtolower($fileinfo['extension']), $fileformats)) { $errors['not_supported_file_format'] = strtolower($fileinfo['extension']) . ' ' . sjb_i18n::getinstance()->gettext(null, 'is not in acceptable file format'); } } if ($file_name == '' && $listingid == 0) { $canappplywithoutresume = false; sjb_event::dispatch('canapplywithoutresume', $canappplywithoutresume); if (!$canappplywithoutresume) { $errors['apply_input_error'] = 'please select file or resume'; } } else if (sjb_applications::isapplied($post['submitted_data']['listing_id'], $current_user_sid) && !is_null($current_user_sid)) { $errors['apply_applied_error'] = 'you applied'; } if (count($errors) == 0 && count($field_errors) == 0) { $res = sjb_applications::create( $post['submitted_data']['listing_id'], $current_user_sid, (isset($post['submitted_data']['id_resume'])) ? $post['submitted_data']['id_resume'] : '', $post['submitted_data']['comments'], $file_name, $mimetype, $id_file, (isset($post['submitted_data']['anonymous'])) ? $post['submitted_data']['anonymous'] : '0', $notregisteruserdata, $post['submitted_data']['questionnaire'], $score ); if ($res) sjb_statistics::addstatistics('apply', $post['submitted_data']['listing_id'], $res); if (isset($post['submitted_data']['id_resume']) && $post['submitted_data']['id_resume'] != 0) { $listing_info = sjb_listingmanager::getlistinginfobysid($post['submitted_data']['id_resume']); $emp_sid = sjb_listingmanager::getusersidbylistingsid($post['submitted_data']['listing_id']); $accessible = sjb_listingmanager::islistingaccessablebyuser($post['submitted_data']['id_resume'], $emp_sid); if (!$accessible) sjb_listingmanager::setlistingaccessibletouser($post['submitted_data']['id_resume'], $emp_sid); } how select multiple resumes , applied?
use this..
<input type="file" name="file_tmp[]" multiple />.. give array of files.
for($i=0; $i < count($_files['file_tmp']['tmp_name']);$i++) { // check if there file in array if(!is_uploaded_file($_files['file_tmp']['tmp_name'][$i])) { $messages[] = 'no file uploaded'; } else { // copy file specified dir if(@copy($_files['file_tmp']['tmp_name'][$i],$upload_dir.'/'.$_files['file_tmp']['name'][$i])) { $messages[] = $_files['file_tmp']['name'][$i].' uploaded'; } else { /*** error message ***/ $messages[] = 'uploading '.$_files['file_tmp']['name'][$i].' failed'; } } } let me know if want further guidance...
Comments
Post a Comment