We made a modulized app in laravel 5.0, So we want to get our css and js files from another directory (non public directory) such as a module directory.
We searched the stacks and couldn't find any solution. How can we do that?
Thanks
hint: the asset() function doesn't work except in public directory.
You have two options:
1.You can setup a route to serve files from your directory.
Route::get('assets/{filename}', function ($filename){
$path = 'path_to_your_folder/'.$filename;
$file = File::get($path);
$type = File::mimeType($path);
$response = Response::make($file, 200);
$response->header("Content-Type", $type);
return $response;
});
2.Make a symbolic link between the directories.
ln -s /path/to/your_assets_folder /path/to/public/assets
Got it from: this similar question
Use url function url('your_address')
Related
Is there is a way to access the storage directory, which is already linked to the public directory in JS?
I'm trying to make an upload image form.
Validation script:
if ($request->hasFile('photos')) {
$marker->photos = $request->photos->store('uploads');
}
It saves image in /storage/app/uploads/
I can't use this image, because website is in public folder, and can't have access to any other folders, so I did php artisan storage:link to create a sublink to storage folder.
Now, how can I access the image using 1) PHP 2) JS?
Yes, you have to use the public disk to store the file:
if ($request->hasFile('photos')) {
$marker->photos = Storage::disk('public')->putFile('uploads', $request->file('photos'));
}
This syntax, similar to the one you are using, it's also possible to specify 'public' disk:
$marker->photos = $request->file('photos')->store(
'uploads', 'public'
);
Then you'll can access to it by the url.
Laravel:
$url = asset('storage/uploads/filename.png');
$url = asset( Storage::url('uploads/filename.png') );
JS:
let imgSrc = "http://yourdomain/storage/uploads/filename.png";
References:
File Storage File Uploads.
File Storage The Public Disk.
File Storage File URLs.
From PHP, you would use something like this to access your storage/ directory:
if(file_exists('storage/app/uploads/photo.jpg')){
$marker->photo = Storage::disk('local')->get('public/app/uploads/photo.jpg');
// or to get the directory, which you can append ->response('png') to the end...
$marker->photo = public_path('storage/app/uploads/photo.jpg');
}
To serve it from JS, you would do something similar, but have a Controller output the image when receiving an AJAX Request. Easiet method to achieve this without all this, if possible, would be through a blade template:
<img src = "{{asset('/storage/app/uploads/photo.jpg')}}">
which generates a link to the uploaded file by Laravel.
I am totally new to ajax. I have a URL that points to a directory on a server and I need to find a way to return the number of files in that directory. I tried both of the "up voted" responses in the link, but no luck. Does anybody have experience with this?
How to get the count of file in a directory using jquery?
At backend server you have to run any of these method depending upon your language from where you can send file count back to ajax call. However client side javascript is not capable of reading directory unless you use file api and ask user to select all files which is really not a solution.
PHP
$directory = "/dir";
$files = scandir($directory);
$num_files = count($files)-2;
NODEJS
var shell = require('shelljs');
var num_files = shell.exec("cd destinationFolder || exit; ls -d -- */ | grep 'page-*' | wc -l", { silent:true }).output;
ASP
int num_files Directory.EnumerateFiles(path, "*.*").Count()
I have a list of mp3 files under my asset folder, I want to list the files and there paths that exist under this directory.
I have tried getAssets() but all what I get is filenames.
is there any other way?
thanks in advance
This question was already answered here in the link below in stackoverflow:
android list files contained in assets subfolder
Then with their names you can access them depend on what they are e.g. If they are image you access them like below:
try {
InputStream im = getAssets().open("image.jpg");
Drawable d = Drawable.createFromStream(im, null);
imageView.setImageDrawable(d);
}
catch(IOException ex) {
return;
}
I have a string to the path of a file, and i would like to get the file. So far i have only found this, which relies on the file being within a specified folder, or a child of this folder.
var rootFolder = Windows.Storage.ApplicationData.current.localFolder;
rootFolder.getFileAsync('MY_FILE_PATH_FROM_ROOT').then(function (file) {
});
By rootFolder points to a folder where the app is installed, something like C:\Program Files....
What if i have a filePath string of something like C:\MyFiles\Picture\Pic_123.png. How would i get this file?
Sorry i am new to WinJs.
Kind of simple once you see the API. Use
Windows.Storage.StorageFile.getFileFromPathAsync('YOUR_FILE_PATH')
.then(function (file) {
});
Hi I've already tried link from github and other SO questions. None of them solved my problem (SO-1 , SO-2, github).
So Here is my code snippet:
require(
[ 'https://blueimp.github.io/JavaScript-Templates/js/tmpl.min.js',
'https://blueimp.github.io/JavaScript-Load-Image/js/load-image.all.min.js',
'https://blueimp.github.io/JavaScript-Canvas-to-Blob/js/canvas-to-blob.min.js',
'upload/jquery.iframe-transport',
'upload/jquery.fileupload-ui'
],function(){
console.log("new action called ");
}
);
in a folder "upload" i've below files:
jquery.fileupload-audio.js
jquery.fileupload-image.js
jquery.fileupload-process.js
jquery.fileupload-ui.js
jquery.fileupload-validate.js
jquery.fileupload-video.js
jquery.fileupload.js
jquery.iframe-transport.js
load-image.js
tmpl.js
canvas-to-blob.js
After adding all above files, still in my console I've bunch of errors. out of them below two are actually doesn't make sense.
js/jquery.fileupload-image.js : 23 'load-image-exif'
js/jquery.fileupload-image.js : 24 'load-image-ios'
I can't find files with those names in official git repo. can anyone suggest an idea how to get it working (a fiddle would be a gret help).
CH
I've manage to get the blueimp fileupload working after exploring every individual files. The problem is coming from require js dependencies, so if u are looking solution to use require js to load blueimp fileupload here is the solution.
Download latest blueimp fileupload release https://github.com/blueimp/jQuery-File-Upload/releases
Remove all unnecessary files (All .html files, .json, .md, server folder, test folder and app.js from js folder). I just personally don't need those file, u can keep them if u want. I just like to keep thing tidy and clean. ^^
I've manually grabbed load-image-exif.js, load-image-ios.js, load-image-meta.js, load-image, tmpl.min.js and put them in vendor folder, where jquery.ui.widget.js is. So i cd to fileupload vendor folder and just curl grab these files like following
curl -O https://raw.githubusercontent.com/blueimp/JavaScript-Load-Image/master/js/load-image-meta.js
curl -O https://raw.githubusercontent.com/blueimp/JavaScript-Load-Image/master/js/load-image-ios.js
curl -O https://raw.githubusercontent.com/blueimp/JavaScript-Load-Image/master/js/load-image-exif.js
curl -O https://raw.githubusercontent.com/blueimp/JavaScript-Load-Image/master/js/load-image.js
curl -O https://raw.githubusercontent.com/blueimp/JavaScript-Templates/master/js/tmpl.min.js
have these path setting in ur require js config
paths: {
jquery: '//code.jquery.com/jquery-1.11.0.min',
// redefined blueimp fileupload path
"jquery.fileupload": "/jquery-file-upload/js/jquery.fileupload",
"jquery.fileupload-ui": "/jquery-file-upload/js/jquery.fileupload-ui",
"jquery.fileupload-image": "/jquery-file-upload/js/jquery.fileupload-image",
"jquery.fileupload-audio": "/jquery-file-upload/js/jquery.fileupload-audio",
"jquery.fileupload-video": "/jquery-file-upload/js/jquery.fileupload-video",
"jquery.fileupload-validate": "/jquery-file-upload/js/jquery.fileupload-validate",
"jquery.fileupload-process": "/jquery-file-upload/js/jquery.fileupload-process",
"jquery.iframe-transport": "/jquery-file-upload/js/jquery.iframe-transport",
"tmpl": "/jquery-file-upload/js/vendor/tmpl.min",
"load-image": "/jquery-file-upload/js/vendor/load-image",
"load-image-ios": "/jquery-file-upload/js/vendor/load-image-ios",
"load-image-exif": "/jquery-file-upload/js/vendor/load-image-exif",
"load-image-meta": "/jquery-file-upload/js/vendor/load-image-meta",
"jquery.ui.widget": "/jquery-file-upload/js/vendor/jquery.ui.widget",
}
in ur app.js or main.js what ever u prefer just require either jquery.fileupload or jquery.fileupload-ui. For me I need to use the image preview and progress tracking and template engine so i'm requiring jquery.fileupload-ui
define([
'jquery',
'jquery.fileupload-ui',
], function($) {
$('#fileupload').fileupload({
// work on ur magic here
});
});