I created a form to send a letter with the ability to attach a file
here is the code
require_once(ABSPATH . "wp-admin" . '/includes/image.php'); require_once(ABSPATH . "wp-admin" . '/includes/file.php'); require_once(ABSPATH . "wp-admin" . '/includes/media.php'); $uploadedfile = $_FILES['file']; $upload_overrides = array( 'test_form' => false ); $movefile = wp_handle_upload( $uploadedfile, $upload_overrides ); if ( $movefile && !isset( $movefile['error'] ) ) { echo "File is valid, and was successfully uploaded.\n"; var_dump( $movefile); } else { echo $movefile['error']; } <input type="file" id="file" name="file" />
after sending I get this error
File is empty. Please upload something more substantial. This couldn’t have been your php.ini or post_max_size.
I checked the php.ini settings, file uploads are not disabled and do not exceed the size. through the admin section I upload files without problems
var_dump($_FILES);
at the beginning of the file receiving script and see what is in the array and where the data will be taken from. - Visman pmenctype='multipart/form-data'
added to theenctype='multipart/form-data'
form? - StasHappyFile is empty
- The file is empty. So the file did not reach the server or reached, but not completely. You can look at the error code: $ _FILES ['file'] ['error'] and find out more specifically which of these misunderstandings occurred. - StasHappyphp
code must be run by condition, rather than directly sculpted beforehtml
output. In all the examples I see this spelling. - Visman pm