Code Igniter File Upload For Autocad - codeigniter

Anyone could help me ? Why dwg extension is read as not allowed types file, while I had write in mimes.php to include dwg extension file as allowed file extension..

You could add the following to the MIME array located at root/application/config/mimes.php
array(
'dwg' => array('application/acad', 'application/x-acad', 'application/autocad_dwg', 'image/x-dwg', 'application/dwg', 'application/x-dwg', 'application/x-autocad', 'image/vnd.dwg', 'drawing/dwg')
);
These are simply all the possible MIME types for a .dwg file.
Now when you are using the file uploading class you can simply add dwg to the array of allowed file types
$this->load->library('upload', array(
'allowed_types' => 'dwg'
));

Related

Laravel: upload folder is created in the wrong directory

I have a form with a file input ready to be saved.
$request->validate([
'name'=> 'required|min:3',
'image'=> 'required|image|mimes:jpeg,png,jpg'
]);
$category = new Category();
$category->name = $request->name;
$path = $request->file('image')->store('categories_images');
$category->image = $path;
What the above code does is that it grabs the image field from the request and save it to the categories_images folder. When I first uploaded a file to test it it created the folder in storage/app.
My problem is that I want to preview the images on my site:
//store.state.serverPath returns: http://localhost:8000 -> this is right
<img :src="`${$store.state.serverPath}/storage/${category.image}`" class="image-wd"/>
When I inspect it in the nrowser it says:
http://localhost:8000/storage/categories_images/adGR57Gq6lNUqRVvEubRDfxNMZzEhya3A7oESUox.png not found
It expects the images in storage/app/public but creates the categories_images folder everytime I upload an image in storage/app. Am I missing something here?
It seems I can't post a comment just as an answer. So let me add my input. Did you create your symbolic link? If not do it now, or just redo it. I had the same issue when i ported my code from mac to windows. Even if all the configuration was done corectly the link was related to my mac. I just fixed that issue now for my code. So thank you for your question.
php artisan storage:link
Also the first parameter of store is the path you want to save the file under storage/public directory. You need to append the directory name in yor url to find the file.
This is the code I use in one of my projects.
$path = isset($validated['document']) ? $path = $request->file('document')->store('pdfs', 'public') : null;
The file will be accessed with the url www.example.com/storage/pdfs/$path
document is the name of file input.
You miss the part of the tutorial where he changed the config -> filesystems.php with this
'local' => [
'driver' => 'local',
'root' => storage_path('app/public'),
],

Laravel txt file is not uploading

In Laravel 5, I want to upload files like pdf, jpeg, and also txt files etc. I see the uploading is working well with the file extension except .txt files. My code is as under;
$validator = Validator::make($request->all(), [
'itemImage' => 'mimes:jpeg,jpg,gif,png,bmp,svg,doc,docx,odt,xls,xlsx,pdf,txt |max:4096'
]);
I also tried by replacing the txt as text/plain but got the same problem.
Remove the space between txt and |.
The validation translator will split rules on |. However, because of the space, the last extension ends in an extra space. And that is why .txt files are not allowed, because they do not end in an extra space.

Deleting file with Laravel

i'm having troble deleting a file from a Laravel Project.
The file is in the /storage/exports directory, it's an excel stored on the disk usingthe Laravel Excel library.
This is my code:
$path = $excel->store('xls', false, true)['full'];
...send the xls via mail....
Storage::delete($path);
When i check the existence of the file with file_exist i get true, so Laravel is able to read the file.
I've also checked the permission for the folder and i give all permissions on this folder using chmod 777
Any ideas?
Thanks!
The storage driver already has an awareness of a root directory, so the $path must be relative, not full. So if your file is in:
/this/is/the/full/path.xls, and the config filesystems.disks.local.root is set to /this/is/the/full, you're essentially having it look for a file in /this/is/the/full/this/is/the/full/path.xls.
You have two options.
1) Add a new driver to that config, and reference it directly:
'custom_location' => [
'driver' => 'local',
'root' => '/some/other/root/path',
]
Storage::driver('custom_location')->delete($relativePathFromRoot)
2) Create a one-off:
$rootPath = '/some/other/root/path';
$client = Storage::createLocalDriver(['root' => $rootPath]);
$client->delete($relativePathFromRoot);
Try storing the file within storage/app/exports. The Storage class's default location to store files is storage/app.
It may be a good idea to instead of using the Excel class to store the file, to instead save the file using the Storage class: Storage::put('exports/excelfile.xls', $fileContents);
Even though you are using Laravel, you can use regular PHP functions.
unlink($path);

Adding Email Attachments From Local Storage

I am using laravel/lumen. I am able to save files using Storage::disk("local")->put(); in my storage directory. However now I want to attach a few of those files to an email and send, this is done with a job the error I get is
lumen.ERROR: exception 'Swift_IoException' with message 'Unable to
open file for reading
Now I read something about symbolic linking which I tried but that simply did not change the result, I was still unable to attach files i n my storage folder to my emails.
This is my directory structure:
/home/xxxxxx/:
-example.app
--storage
---app
----public
-public_html
--example.app
---storage
Attaching the file like this:
foreach ($params["attachments"] as $attachment) {
$mail->attach($attachment["file"], [
'as' => $attachment["name"],
'mime' => $attachment["mime"]
]);
}
You've already realized that attach() method expects the full path to the file. However, others may find useful know how to achieve that. So, in case you're using the default settings for local store, you may be able to get the full path by calling the storage_path() helper. This way:
/*
* This will return the full path to the file:
*
* /path/to/laravel/storage/app/attachment/path
*/
storage_path('app/' . $attachment['file']);
Okay so apparently swift mailer fails when you pass a full url instead of the real path to the file. Didn't know this, don't know if it's a bug or it was done by design.

In OctoberCMS Multiple File Upload In Admin Section

I am trying to upload multiple files in my custom component. First I have tried with mediafinder then fileupload but seems like nothing working.
I have google for admin section file upload.but there is no demo/example of multiple file upload in which user can upload multiple images and which is store uploaded file name in separate table.
Can anyone give me any demo/sample link of multiple file upload in admin section?
To attach file to a model you need to use System\Models\File in a attachOne or attachMany relation
public $attachOne = [
'myfile' => 'System\Models\File'
];
public $attachMany = [
'myfiles' => 'System\Models\File'
];
documentation : https://octobercms.com/docs/database/attachments
Add this myFile or myFiles into you backend form by editing the fields.yaml file.
myFile :
label: myFile
type: fileupload
mode: file
fileupload - renders a file uploader for images or regular files. The field name must use an attachOne or attachMany relation.
The result would be

Resources