Ckeditor 5 file uploading adapter error - php

I'm using ckeditor classic 5, and i'm trying to upload images in it. I downloaded php lib Ckfinder3 php connector, set config.
When i'm trying to load image i have a massage: Cannot upload file *filename*.
Interesting moment, that they are fisically loaded on server: i can view it in directory, that set in my config file and this files are correct:
/var/www/projectfiles/downloadfiles/
The next step i'm check permission and groups: it's www-data 0777.
What can be a reason? Can you give some advice or solution?
Thanks!
UPD: init function
ClassicEditor
.create( document.querySelector( '#material_preview' ), {
ckfinder: {
uploadUrl: '/ckfinder/connector/?command=QuickUpload&type=Images'
}
} )
.catch( error => {
console.error( error );
} );
php config:
$config['authentication'] = function () {
return true;
};
$config['backends']['default'] = array(
'name' => 'default',
'adapter' => 'local',
'baseUrl' => 'http://files.project.com/downloadfiles/',
'root' => '/var/www/projectfiles/downloadfiles/',
'chmodFiles' => 0777,
'chmodFolders' => 0777,
'filesystemEncoding' => 'UTF-8'
);

The connector path looks invalid. For PHP it should be something like:
'/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files'
Please have a look at CKEditor integration examples in CKFinder demo: https://ckeditor.com/docs/ckfinder/demo/ckfinder3/samples/ckeditor.html

Finally i got it!
The connector path is valid. The problem was in cache folder's permisson in laravel. Be glad if it helps you.

Related

Laravel vue - upload image and retrieve it

i have table 'case' that contains an image column, i want users to insert into the case table and be able to upload an image, on the home page users can view cases along with image of each case.
so far i have tried:
public function createcase(Request $request){
$validator = Validator::make($request->all(), [
'title' => 'required',
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
'description' => 'required',
'caseTypeId' => 'required',
'amountneeded' =>'required',
'uid' => 'required',
'visible' => 'required',
]);
if ($validator->fails()) {
return response()->json(['error'=>$validator->errors()], 401);
}
$image = $request->file('image');
$path = $image->store('public');
$case = casee::create([
'title' => $request->title,
'description' => $request->description,
'caseTypeId' => $request->caseTypeId,
'amountneeded' => $request->amountneeded,
'uid' => $request->uid,
'visible' => $request->visible,
'image' => $path,
]);
return response()->json(['image' => $image]);
to upload:
<input type="file" id="image" #change="onFileChange" />
methods: {
onFileChange(e) {
this.image = e.target.files[0];
},
async postcase() {
const formData = new FormData();
formData.append('title', this.title);
formData.append('description', this.description);
formData.append('amountneeded', this.amountneeded);
formData.append('caseTypeId', this.selectedcasetype);
formData.append('uid', this.uid);
formData.append('visible', 1);
formData.append('image', this.image);
try {
await axios.post('http://127.0.0.1:8000/api/postcase', formData).then(response => {
console.log(response.data);
})
} catch (error) {
console.log(response.data);
}
}
to retrieve:
<v-flex class="ma-2" v-for="casee in cases" :key="casee.id" lg3 xs12 md6 sm4>
<img v-if="casee.image" :src="'/storage/' + casee.image" alt="Case Image">
mounted(){
this.getcases();
},
methods:{
async getcases(){
try {
const response = await axios.get('http://127.0.0.1:8000/api/cases');
this.cases = response.data.cases;
console.log(this.cases);
} catch (error) {
console.log(error);
}
},
everything works fine except for the image. it returns the error Cannot GET /storage/public/CQu7g4X98APkiMSbCGlqyiJhaXzLaEk8P0pZXaD3.jpg when i try to retrieve it
Frontend couldn't access filesystem as "/storage/public/FILENAME.jpg".
If you are based on Laravel 9.x, and didn't change any filesystem default settings, your file will stored under "<project root>/storage/app/public/", it's filesystem default path, but frontend can only access your "<project root>/public/" folder, do check list as below might help you slove issue.
1.Make sure you executed php artisan storage:link command, and it will created a symbolic link from your storage path to public path.
If you didn't change settings, it will create link from "<project root>/storage/app/public" to "<project root>/public/storage", once you done command you can see your storage folder under public folder.
You can access "<APP_URL>/storage/FILENAME.jpg" to see if link create success or not, if you ain't get 404 means your link created as well as it should be.
2. Use laravel helper to generate storage url.
Use the asset() helper create a URL to the files.
Your files will under "<project root>/public/storage" after step 1, and your nginx root will access public as default, so you don't need public as your url path anymore.
asset('storage/FILENAME.jpg');
// output will be "<APP_URL>/storage/FILENAME.jpg"
3. (Not required) Check if laravel cached your view.
For some new developer of laravel didn't notice that laravel will cached your view, and they keep thinking that code doesn't work.
You can easily check if laravel cached view by php artisan about command if you are using latest laravel version, and use php artisan view:clear to clear view cache.
Make sure that the storage directory is correctly linked to the public.
You can run this command to make it automatically:
php artisan storage:link
heres how i solved it if anyone comes across this issue :
based on the previous answers:
1. php artisan storage:link
replace 'image' => $path to 'image' => basename($path).
3.<img :src="'http://127.0.0.1:8000/storage/' + casee.image" alt="Case Image">

Yii2 uploaded image doesn't show up

I use this yii2 module for an image uploading purposes.
My upload folder is:
C:\XAMPP\HTDOCS\MYAPPNAME\WEB\UPLOAD
├───cache
├───global
└───store
└───Products
└───Product15
Where store is the folder for original pictures and the cache is for the resized ones. yii2-images is configured like this:
'yii2images' => [
'class' => 'rico\yii2images\Module',
//be sure, that permissions ok
//if you cant avoid permission errors you have to create "images" folder in web root manually and set 777 permissions
'imagesStorePath' => 'upload/store', //path to origin images
'imagesCachePath' => 'upload/cache', //path to resized copies
'graphicsLibrary' => 'GD', //but really its better to use 'Imagick'
'placeHolderPath' => '#webroot/upload/store/no-image.png', // if you want to get placeholder when image not exists, string will be processed by Yii::getAlias
],
and my Product model upload method is:
public function upload()
{
if ($this->validate()) {
$path = 'upload/store/' . $this->image->baseName . '.' . $this->image->extension;
$this->image->saveAs($path);
$this->attachImage($path);
#unlink($path);
return true;
} else {
return false;
}
}
Uploading images work. I mean, they fisically appear where they should. I load image
<?php $img = $model->getImage(); ?>
and in my DetailView widget instead of 'img':
[
'attribute' => 'image',
'value' => "<img src='{$img->getUrl()}'>",
'format' => 'html',
],
And what I get instead of a rendered image is:
image-by-item-and-alias?item=Product15&dirtyAlias=71273544a6-1.jpg
I have no idea where this "image-by-item-and-aliasitem=Product15&dirtyAlias?" part even comes from when it actually must be something like:
Products\Product15\71273544a6-1.jpg
and given format html parameter it must therefore render an image.
Can you please pinpoint me to the source of this error?

laravel doesn't upload images on server

I can upload my images while i'm working on local but when I moved my site to host it doesn't upload images while get names of them in database,
my filesystems.php
'default' => env('FILESYSTEM_DRIVER', 'local'),
disks' => [
'local' => [
'driver' => 'local',
'root' => public_path('images/'),
],
....
sample of my upload codes:
if ($request->hasFile('imageOne')) {
$imageOne = $request->file('imageOne');
$filename = 'productone' . '-' . time() . '.' . $imageOne->getClientOriginalExtension();
$location = public_path('images/');
$request->file('imageOne')->move($location, $filename);
$product->imageOne = $filename;
}
Issue:
In host i get uploaded image name in database, but no image in my
public/images folder.
any idea?
UPDATE
I found interesting folder in my host, as I moved all my public folder files to server public_html now it created another folder in my root called public and inside that has images folder including all images i uploaded so far!
Questions:
Why laravel created new public/images folder in my root instead of
using my public_html?
How to fix it?
SOLVED
I added this code to my public_html/index.php file and it's working now.
// set the public path to this directory
$app->bind('path.public', function() {
return __DIR__;
});
Hope it helps.
I change the public path inside my save image controller to look like this:
if (request()->imagefile->move(public_path('../../public_html/destination'), $imageName))
echo "Yap";
else echo "Nop";

load selected pre-existing files in blueimp

I am able to load all the files in a directory using blueimp file uploading plugin.
I just want to select only few of the files using filenames in that.
I know that get method of uploadhandler returns all the files in given directory but is there any way to select only few files?
This is what I have done to get all files..
public function getFile() {
extract($this -> reqData);
require_once ('path/to/UploadHandler.php');
$options = array(
'script_url' => "path to uploadhandler",
'upload_dir' => "xxxxxxx",
'upload_url' => "xxxxxxx",
'type' => 'project_files'
);
$upload_handler = new UploadHandler($options);
exit;
}
Please don't give negative remarks just because my editing is poor.
Thanks everybody...

jQuery FileUpload syntax error

While implementing jQuery FileUpload in CodeIgniter everything seems to work, no javascript errors and the files get created in the default folders (chmod'ed 0777), but there are two issues.
1. I can't override the default options on the PHP handler provided by the package. Here is the Controller action I'm using to do so, none of the parameters passed are actually applied, if I dump the options within the UploadHandler I get the default options.
public function fileupload()
{
if ($this->input->is_ajax_request())
{
# load library
$this->load->library('UploadHandler');
# upload file
$upload_handler = new UploadHandler(array(
'upload_dir' => FCPATH.'upload/realty/'.$this->_user->id.'/',
'mkdir_mode' => 0777,
'accept_file_types' => '/\.(gif|jpe?g|png)$/i',
));
}
else
{
redirect('error/page_not_found');
}
}
2. The script is throwing a error when a file finishes uploading :
SyntaxError: Unexpected token {
Here is the response of an example request :
{"files":[{"name":"nebula-ngc-281.jpg","size":590295,"type":"image\/jpeg","url":"http:\/\/test.filipematias.info\/mercadoimobiliario\/admin\/files\/nebula-ngc-281.jpg","thumbnailUrl":"http:\/\/test.filipematias.info\/mercadoimobiliario\/admin\/files\/thumbnail\/nebula-ngc-281.jpg","deleteUrl":"http:\/\/test.filipematias.info\/mercadoimobiliario\/admin\/?file=nebula-ngc-281.jpg","deleteType":"DELETE"}]}{"files":[{"name":"nebula-ngc-281 (1).jpg","size":0,"type":"image\/jpeg","error":"File upload aborted","deleteUrl":"http:\/\/test.filipematias.info\/mercadoimobiliario\/admin\/?file=nebula-ngc-281%20%281%29.jpg","deleteType":"DELETE"}]}
According to this document Creating Libraries check how we can pass the param in library
so it would be:-
$options= array(
'upload_dir' => FCPATH.'upload/realty/'.$this->_user->id.'/',
'mkdir_mode' => 0777,
'accept_file_types' => '/\.(gif|jpe?g|png)$/i',
));
$this->load->library('UploadHandler',$options);

Categories