I have a custom page template. This template have a custom form that user can upload a file. Now, the uploaded file/s will not upload in the MySQL but in the file system/local folder (local computer).
I already have a PHP snippet, but the code is not working I’m getting an errors.
How to fix this?
Snippet:
if(isset($_POST['submit'])){
$lastName = isset($_POST['lastName']) ? $_POST['lastName'] : '';
$resumeFile = isset($_FILE['resumeFile']['name']) ? $_FILE['resumeFile']['name']: '';
$info = pathinfo($_FILES['resumeFile']['name']);
$ext = $info['extension'];
$file_rename= $lastName.$ext;
$target = 'C://xampp/htdocs/files/'.$file_rename;
move_uploaded_file($_FILES['resumeFile']['tmp_name'], $target);
}
Errors:
Notice: Undefined index: resumeFile .... on line 130
Notice: Undefined index: extension .... on line 131
Notice: Undefined index: resumeFile .... on line 135
Try the following snippet, to upload files on different directory other than default
uploads
directory.wp_handle_upload
will return an object which contains the following propertiesIf
wp_handle_upload
fails it will return error object, you can check for failed upload like this