CodeIgniter Forums
File Upload - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: File Upload (/showthread.php?tid=68407)



File Upload - scalla - 07-06-2017

Good day, does anyone have a clue how the file upload for igniter4 is supposed to work??

been having lot of failed attempts


RE: File Upload - kilishan - 07-06-2017

Looks like there was an issue with file extensions on uploaded files. That should be fixed now. Please download the latest version and try again.

Here's some extremely ugly code to give you an idea of some of the things you can do:

Code:
public function upload()
{
if  ($this->request->getMethod() == 'post')
{
$this->validate([
'avatar' => 'uploaded[avatar]|ext_in[avatar,png,jpg,jpeg,gif]'
]);

/**
* @var \CodeIgniter\HTTP\Files\UploadedFile
*/
$file = $this->request->getFile('avatar');

echo "Name: {$file->getName()}<br/>";
echo "Temp Name: {$file->getTempName()}<br/>";
echo "Random Name: {$file->getRandomName()}<br/>";
echo "Extension: {$file->getExtension()}<br/>";
echo "Client Extension: {$file->getClientExtension()}<br/>";
echo "Guessed Extension: {$file->guessExtension()}<br/>";
echo "MimeType: {$file->getMimeType()}<br/>";
echo "IsValid: {$file->isValid()}<br/>";
echo "Size (b): {$file->getSize()}<br/>";
echo "Size (kb): {$file->getSize('kb')}<br/>";
echo "Size (mb): {$file->getSize('mb')}<br/>";
echo "Size (mb): {$file->getSize('mb')}<br/>";
echo "Path: {$file->getPath()}<br/>";
echo "RealPath: {$file->getRealPath()}<br/>";
echo "Filename: {$file->getFilename()}<br/>";
echo "Basename: {$file->getBasename()}<br/>";
echo "Pathname: {$file->getPathname()}<br/>";
echo "Permissions: {$file->getPerms()}<br/>";
echo "Inode: {$file->getInode()}<br/>";
echo "Owner: {$file->getOwner()}<br/>";
echo "Group: {$file->getGroup()}<br/>";
echo "ATime: {$file->getATime()}<br/>";
echo "MTime: {$file->getMTime()}<br/>";
echo "CTime: {$file->getCTime()}<br/>";

                       $file->move($destination);

dd($file);
}

echo <<<EOF
<!doctype html>
<html>
<body>

<form action="" method="post" enctype="multipart/form-data">

<input type="file" name="avatar">

<input type="submit" value="Upload">

</form>

</body>
</html>

EOF;
;
}

Oh - and remember it's pre-alpha quality software at the moment. Bugs should be expected. Any help diagnosing those bugs is always helpful.