dongquqiao2010 2014-03-11 13:26
浏览 33
已采纳

如何在php中使用smarty上传多个文件?

I make a select box in which i select different resumes to apply on the same job but when i applying jobs it gives me error like this "You Already Applied"

Here is my 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 is not valid]]
                {elseif $error_code eq 'SEND_ERROR'} [[There was an error while sending your 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 your resume]]:</div>
                <div class="inputField">
                    <select name="id_resume" multiple="multiple">
                        <option value="0" selected="selected">[[Select your resume]]</option>
                        {html_options options=$resume selected=$request.id_resume}
                    </select>
                    <br />or
                </div>
            </fieldset>
        {/if}
        <fieldset>
            <div class="inputName">[[Attach your 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">&nbsp;</div>
            <div class="inputButton"><input id="SubmitButton" type="submit" value="[[Send]]" onclick="return applySubmit();"/></div>
        </fieldset>
    </form>
{/if}
 </div>

and here is my 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 be 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 an 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 already 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 i select multiple resumes and then applied?

  • 写回答

1条回答 默认 最新

  • dongshaidu2456 2014-03-11 13:42
    关注

    use this..

    <input type="file" name="file_tmp[]" multiple />.. this will give you an array of files.

     for($i=0; $i < count($_FILES['file_tmp']['tmp_name']);$i++)
        {
            // check if there is a file in the array
            if(!is_uploaded_file($_FILES['file_tmp']['tmp_name'][$i]))
            {
                $messages[] = 'No file uploaded';
            }
            else
            {
                // copy the file to the 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
                {
                    /*** an error message ***/
                    $messages[] = 'Uploading '.$_FILES['file_tmp']['name'][$i].' Failed';
                }
            }
        }
    

    let me know if you want any further guidance...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?