if(isset($_POST['submit'])){ $file_name = $_FILES['file']['name']; $file_tmp = $_FILES['file']['tmp_name']; $file_type = $_FILES['file']['type']; $file_size = $_FILES['file']['size']; move_uploaded_file($file_tmp,"uploads/".$file_name); }
if(isset($_POST['submit'])){ $file_name = $_FILES['file']['name']; $file_tmp = $_FILES['file']['tmp_name']; $file_type = $_FILES['file']['type']; $file_size = $_FILES['file']['size']; $file_ext = strtolower(end(explode('.',$_FILES['file']['name']))); $extensions= array("jpeg","jpg","png"); if(in_array($file_ext,$extensions)=== false){ echo "Extension not allowed, please choose a JPEG or PNG file."; } if($file_size > 2097152){ echo 'File size must be less than 2 MB'; } move_uploaded_file($file_tmp,"uploads/".$file_name); }This code will first check the file extension and only allow valid extensions (jpeg, jpg, png), it will also output an error message if an incorrect file type is uploaded. Next, it will check the file size and only upload the file if it is less than 2MB. Package Library Name: Joomla Framework (JFile)