Welcome Guest, Not a member yet? Register   Sign In
File upload validation still incorrect?
#1
Question 

Hi, 
the issue I'm facing relates to this thread: https://forum.codeigniter.com/thread-76071-page-2.html 
I'm using CI 4.1.4 (latest currently). Simple code to move uploaded file:
PHP Code:
$file $this->request->getFile('file');
$file->move($uploadPath);
if (
$file->isValid()){ 
...
} else {
   log_message('error', $file->getErrorString().' ('.$file->getError().')');


When I do upload (via Ajax), file is written successfully to the server, no error is thrown. However, this code puts this in logs:

Quote:The file uploaded with success. (0)

So, $file->isValid() actually returns the opposite: it returns false on successful upload. Is it known issue?
Reply
#2

i'm using Ci4 and having no problems with upload .

I start with :

Code:
$file = $this->request->getFile('userfile');
                $name= $file->getName();
                $tempfile = $file->getTempName();

the move bit is:

Code:
$file->move('blogImages',$name);

now with ->isValid()

personally i don't like it, because i'm a control freak ,so i don't use it . instead i have a utiliy class which for the image does a series of checks


eg



Code:
function getFileSize($tmpName)
    {
    $this->fileTmpName = $tmpName;
    $this->fileSize= filesize($this->fileTmpName);
    return $this->fileSize;        
        
   }

So first i check to see if image already exists in directory blogImages, i decide 250 kb is maximum to upload, if img bigger than that i message is fed back to form for upl0ading image , that image is too big , i check extension of image . By doing my own checks i understand it , so i know how to update and it works the way i want
CMS CI4     I use Arch Linux by the way 

Reply




Theme © iAndrew 2016 - Forum software by © MyBB