无法在wordpress

时间:2017-09-22 07:40:51

标签: php wordpress pdf file-upload

我正在制作礼品券插件,如果顾客想要送他/她的朋友。因此,有些人可能需要发送pdf文件(这不是必填字段,但如果有人需要它。)以下是我的上传代码:[我要上传pdf /文件夹中的文件]

// pdf file

    echo $pdf_file = $_POST['hidden_pdf_file'] . "<br>";
    echo $pdf_file_name = $_POST['hidden_pdf_name'] . "<br>";

    echo  $path=plugin_dir_url( __FILE__ )."pdf/";
  // Use the WordPress API to upload the file
        require_once( ABSPATH . 'wp-admin/includes/file.php' );
            $uploadedfile = $pdf_file_name;
            $upload_overrides = array( 'test_form' => false );
            $movefile = wp_handle_upload( $uploadedfile, $upload_overrides );
            if ( $movefile ) {
                echo "File is valid, and was successfully uploaded.\n";
                var_dump( $movefile);
            } else {
                echo "Possible file upload attack!\n";
            }
      // end pdf upload

错误消息

http://test.giitcomputer.com/wp-content/plugins/simple-gift-cards/pdf/

文件有效且已成功上传。但“pdf /”目录中没有文件。

注意:它显示文件已成功上传。但是,看到第二个错误....

array(1) { ["error"]=> string(212) "File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini." }

1 个答案:

答案 0 :(得分:0)

您必须增加上传最大文件大小。

  1. 在functions.php文件中添加以下语句。

    @ini_set(&#39; upload_max_size&#39;,&#39; 128M&#39;);

    @ini_set(&#39; post_max_size&#39;,&#39; 128M&#39;);

    @ini_set(&#39; max_execution_time&#39;,&#39; 300&#39;);

    1. 在htaccess文件中添加以下语句。

      php_value upload_max_filesize 128M

      php_value post_max_size 128M

      php_value max_execution_time 300

      php_value max_input_time 300