zoukankan      html  css  js  c++  java
  • drupal文件上传表单的例子

    function upload_form() {
        $form = array();
        // If this #attribute is not present, upload will fail on submit
        $form['#attributes']['enctype'] = 'multipart/form-data';
        $form['file_upload'] = array(
                '#title' => t('Upload file'),
                '#type'  => 'file',
        );
        $form['submit_upload'] = array(
                '#type'  =>  'submit',
                '#value'  =>  'Submit'
        );
        return $form;
    }
    
    function upload_submit($form, &$form_state) {
        $validators = array();
        $dest = file_directory_path();
        $file = file_save_upload('file_upload', $validators, $dest);
        //$file will be 0 if the upload doesn't exist, or the $dest directory
        //isn't writable
        if ($file != 0) {
            $file->filepath; // 文件相对路径
        }
        else {
            form_set_error('myform', t("Failed to save the file."));
        }
    }
    
  • 相关阅读:
    7月17日
    7月16日学习记录
    7月15日学习记录
    git 学习
    投稿相关
    ubuntu16.04 安装以及要做的事情
    python学习使用
    图像相关
    不识别移动硬盘
    深度学习
  • 原文地址:https://www.cnblogs.com/catcat811/p/1951638.html
Copyright © 2011-2022 走看看