/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
KEEP FOR LATER USE! $error = $this->handleFileUpload($importFile, $importFile['name']); function handleFileUpload($fileData, $fileName) { $error = false; //Get file type //If size is provided for validation check with that size. Else compare the size with INI file if (($this->validateFile['size'] && $fileData['size'] > $this->validateFile['size']) || $fileData['error'] == UPLOAD_ERR_INI_SIZE) { $error = 'File is too large to upload'; } elseif ($this->validateFile['type'] && (strpos($this->validateFile['type'], strtolower($typeArr[1])) === false)) { //File type is not the one we are going to accept. Error!! $error = 'Invalid file type'; } else { //Data looks OK at this stage. Let's proceed. if ($fileData['error'] == UPLOAD_ERR_OK) { //Oops!! File size is zero. Error! if ($fileData['size'] == 0) { $error = 'Zero size file found.'; } else { { //Finally we can upload file now. Let's do it and return without errors if success in moving. { $error = true; } } else { $error = true; } } } } return $error; }