3
votes

I am working on Gift voucher plugin where if a customer wants to gift his/her friend. Hence, some may need to send pdf files( this is not the mandatory field, but if someone needs it. ) So following is my uploading code:[ I am going to upload files in pdf/ folder ]

// 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

ERROR MESSAGE

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

File is valid and was successfully uploaded.But There is no file in the "pdf/" directory.

NOTE: IT SHOWS FILE UPLOADED SUCCESSFULLY.BUT, SEE SECOND ERROR....

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
Is your file uploaded? Can you share the link of the file from the uploads folder? something like test.giitcomputer.com/wp-content/uploads/2017/09/gift.pdf ? is the file there? - Kiran Dash
@KiranDash Thanks for your answer. But I have mentioned in the question that my "pdf/" folder is empty. It shows "This directory is empty." in the pdf folder. NO FILE IS UPLOADED. But don,t know why it shows "File is valid and was successfully uploaded." Because of this issue i have posted this question. - lmp kojar
Did you try increasing the post_max_size in php.ini file? - Kiran Dash
file_uploads = on, upload_max_filesize = 1000M, post_max_filesize = 2000M, memory_limit = 3000M, max_execution_time = 180. This is my php5.ini file. previously it is php.ini. But it didn't worked,hence i renamed it to php5.ini. I am working on a plugin and my php5.ini file is located in public_html/test/wp-admin folder. - lmp kojar
@KiranDash I think this is not an issue with the file size. Because my pdf file is of 32kb. Also I tried uploading different pdf folders to make sure that this is not an issue with file size. - lmp kojar

1 Answers

0
votes

You have to increse upload max filesize.

  1. Add below statement in the functions.php file.

    @ini_set( 'upload_max_size' , '128M' );

    @ini_set( 'post_max_size', '128M');

    @ini_set( 'max_execution_time', '300' );

Or

  1. Add below statement in the htaccess file.

    php_value upload_max_filesize 128M

    php_value post_max_size 128M

    php_value max_execution_time 300

    php_value max_input_time 300