I need help when I try to upload an image CodeIgnite4 - file-upload

I need help when I try to upload an image
I get this error and I don't understand why
avatar is not a valid uploaded file.
my code in controller
rules:
'avatar' => [
'rules' => 'required|uploaded[avatar]|max_size[avatar,1024]|ext_in[avatar,jpg,jpeg,png]',
'errors' => [
'required' => lang('Core.Auth.Error.required'),
]
],
upload:
if (!$this->validate($rules)) {
$data['validation'] = $this->validator;
} else {
$avatar = $this->request->getFile('avatar');
$newName = $avatar->getRandomName();
$avatar->move(WRITEPATH.'uploads', $newName);
$filepath = base_url()."/selfie/".$newName;
my php.ini
upload_max_filesize = 1G
post_max_size = 1G
memory_limit = 1G

From CodeIgniter documentation:
The uploaded rule fails if the name of the parameter does not match the name of any uploaded files.
The exact error message you posted will appear if this rule cannot be satisfied
Double check your HTML <input> tag and make sure that both name attribute of this tag and the name passed to uploaded rule are the same, e.g.:
// In the HTML
<input type="file" name="avatar">
// In the controller
$this->validate([
'avatar' => 'required|uploaded[avatar]|max_size[avatar,1024]|ext_in[avatar,jpg,jpeg,png]'
]);

Related

When i download file programmatically from s3 bucket, It gives me error It looks like we don't support this file format

When I download file from s3 bucket, I am using aws-sdk for that, it downloads the files but when i open that file it says It looks like we don't support this file format, here is my full code of it, can anyone please check my code and help me why image is doesn't open the image, my wholde code is in PHP, It looks like small error but doesn't working for me
$bucket = '*****';
$keyname = '1560346461616.jpg';
$s3 = new S3Client([
'version' => 'latest',
'region' => '******',
'credentials' => [
'key' => '******',
'secret' => '******',
],
]);
$result = $s3->getObject([
'Bucket' => $bucket,
'Key' => $keyname,
]);
header("Content-Type: {$result['ContentType']}");
header('Content-Disposition: attachment; filename='.$keyname);
echo $result['Body'];
} catch (Exception $e) {
echo $e->getMessage() . PHP_EOL;
}
Check the content type of your .jpg file stored in s3. Ensure the metadata for this object says image/jpeg.I don't think it is related to the object you downloaded,maybe the download file was corrupted.

Yii2 Upload video file return error 400

I use Yii2 and want to upload video file .. with images i do not have problems, but when i try to upload video it is return error 400 ... i read two similar question like mine, but they have not answers ... if i miss something?
view:
$childVideo = array();
$model->getErrors();
$count = 0;
if(isset($modelVideo) and $modelVideo->hasVideo()){
$count = 1;
$childVideo = $model->getKartikPhotos();
}else{
echo '<img src="/images/video.jpg" style="width: 15%" />';
}
echo '<div class="col-xs-12 col-sm-12">';
echo $form->field($model, 'videoFiles[]')->widget(FileInput::classname(), [
'options' => [
'multiple' => true,
'disabled' => ((Yii::$app->params['numberUserVideo'] - $count) == 0) ? true : false,
],
'pluginOptions' => [
'fileActionSettings' => [
'removeIcon' => '<i class="fa fa-trash"></i> ',
],
'initialPreview' => $childVideo,
'showRemove' => false,
'showUpload' => false,
'allowedFileExtensions' => Yii::$app->params['allowedUserVideoExtensions'],
'maxFileCount' => Yii::$app->params['numberUserVideo'] - $count,
],
]);
echo '</div>';
and in controller when i try to var_dump($_POST) it is show error 400 ...
You will need to set the values of the upload_max_filesize & post_max_size variables in php.ini config file.
; Maximum allowed size upload_max_filesize = 100M
; Must be greater than or equal to upload_max_filesize post_max_size =
100M
Use a common sense value for the uploads.
After modifying php.ini file(s), restart your server to use new configuration.
If you have a hosted system you will need to ask your host service to increase the values.

File not uploading to s3 bucket using yii2tech/file-storage extension

I'm trying to upload file to my amazon s3 bucket.
My config looks like this
'fileStorage' => [
'class' => 'yii2tech\filestorage\amazon\Storage',
'awsKey' => 'dota2',
'awsSecretKey' => 'dota2',
'buckets' => [
'webfiles' => [
'fileSubDirTemplate' => '{ext}/{^name}/{^^name}',
'region' => 'us_e1',
'acl' => 'public',
],
]
],
My upload function looks like this
$bucket = Yii::$app->fileStorage->getBucket('webfiles');
$bucket->copyFileIn('/var/www/html/vasttag/web/', 'samplefinal.mp4');
$result= var_dump($bucket->fileExists('samplefinal.mp4'));
echo $result;
I get result as false. Yes I have double checked my path and my filename. Its perfectly fine. Anyone know where Im going wrong?

UploadFile big size inYii2

When I try to upload a file more than about 100MB by yii\web\UploadedFile the file isn't uploaded. But all fields become empty and each field has the validation error:
field cannot be blank
This is my validation rules:
public function rules() {
return [
[['name_promo_file', 'description_promo_file', 'url_promo_file', 'size_promo_file', 'lang_promo_file'], 'required'],
[['date_upload_promo_file'], 'safe'],
[['size_promo_file'], 'integer'],
[['lang_promo_file'], 'string'],
[['name_promo_file', 'description_promo_file', 'url_promo_file'], 'string', 'max' => 255],
[['imagePromo'], 'file', 'skipOnEmpty' => false, 'extensions' => 'pdf doc png, jpg, jpeg']
];
}`
This is my php.ini setting
upload_max_filesize = 256M
post_max_size = 256M
max_execution_time = 60
How can I solve this?
I was facing the same problem but i solved by using kartiks file input widget and increasing the size in php.ini ,Here you please seperate the extensions as pdf,docx,....please do a reply if the problem is not solved.hope we can solve it.

dropzone.js doesnt upload .doc,.xls,.xlsx file formats

i have use dropzone extension to upload images. it work like charm. but i want to upload document files doc,docx,xls,xlsx.
$this->widget('ext.dropzone.EDropzone', array(
'model' => $model,
'attribute' => 'image_name',
'url' => Yii::app()->request->baseUrl.'/jobMaster/ImageUpload',
'mimeTypes' => array('image/jpeg', 'image/png','image/jpg'),
'onSuccess' => 'succcesupload',
//'maxFilesize'=> 5,
'options' => array(
'addRemoveLinks'=> true,
'removedfile'=> "js:function(file) {
var name = file.name;
$.ajax({
type: 'POST',
url: '".$this->createUrl('/jobMaster/deleteImageUpload')."',
data: 'id='+name,
dataType: 'html'
});
var _ref;
return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0;
}"
)
));
But i don't know how to change in this widget.
i change
'mimeTypes' => array('image/jpeg', 'image/png','image/jpg','file/doc','file/xls','file/xlsx','file/docx'),
but it doesn't work. Any answer?
Here i got solution
'mimeTypes' => array('image/jpeg', 'image/png','image/jpg','application/vnd.ms-excel','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/docx','application/pdf','text/plain','application/msword','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'),
Here i mentioned which mimeType is used for which extension.
For .docx -
application/vnd.openxmlformats-officedocument.wordprocessingml.document
For .xlxs -
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
For .doc - application/msword
Here is full list for MIME types of different file extensions.
I found issue with .docx, a console.log() of the mime type returned this:
application/vnd.openxmlformats-officedocument.wordprocessingml.d
Hope that helps someone. It fixed the issue for me