I want in Yii2 a simple
[a href="C:/Vo/AGO/2015.pdf">2015 [/a> ([ must be a <)
on one of my forms.
I don't want to upload the file, because the pdf (help) file is updated by an external organisation (instead of C: the pad is a server, but for test reasons I use C:), and I have to display a lot of files managed by that organisation.
So I use:
Html::a("2015", "C:/Vo/Ago/2015.pdf")
When I run the application and I inspect via show source I see
[a href="C:/Vo/Ago/2015.pdf">2015[/a>
But if I click the link on my form, nothing happens!
(When I do the same thing in a simple html document - not yii2 - the pdf opens)
If I copy right-click and copy the link I get:
file:///C:/Vo/Ago/2015.pdf
So, what am I missing?
Yes I'am new in Yii2 and I searched a lot on internet to find a solution.
If this is already asked, excuse me, a reference to the solution would then be welcome...
Thanks,
Chris G.M. Logghe
Because you are trying to link "local" file on browser.
Some browsers, like modern versions of Chrome, will even refuse to
cross from the http protocol to the file protocol, so you'd better
make sure you open this locally using the file protocol if you want to
do this stuff at all.
See here for more details.
The best option for you is to create action on controller and perform download file there.
In your view:
$data = 'C:/data/mydata.log';
echo Html::a('Download', ['sample-download', 'filename' => $data], ['target' => '_blank']);
In your controller:
public function actionSampleDownload($filename)
{
ob_clean();
\Yii::$app->response->sendFile($filename)->send();
}
Of course, you must limit to specific directory rather than user give full access to filename.
Related
I am trying to find the best way to host a bunch of pdfs(and other files potentially) on my synology DS1821+ that can be accessed by a URL so employees can access them by scanning a QR code. The files should be available to any device connected to our WiFi.
I was able to achieve this quite easily using WordPress and simply uploading the files to the "Media Library" And converting the URL to QR code using my web browser.
Here is an example of one of the URLs provided:
http://10-0-1-128.synologynas.direct.quickconnect.to/wordpress/wp-content/uploads/2022/10/F09042-fix.pdf
this also works:
http://10.0.1.128/wordpress/wp-content/uploads/2022/10/F09042-fix.pdf
However, since we would be printing potentially thousands of QR codes to be used around the factory for years to come I need the URL to be something I can control manually, without stuff like "2022" in it so that if someday we switch to different software/hardware we can replicate the same structure so as not to need to reprint and redistribute thousands of QR codes.
I see the application "File Station" on my NAS and this is close to what I want but not quite. There I can right click a file -> share ->QR code and it returns something like this:
http://gofile.me/73nWA/C8AYNuBpv
Pretty cool, but again the URL is not something I can control, and also it uses some advanced voodoo to make the link work anywhere on the internet and these need to only work on our local network.
Any thoughts on the simplest way to achieve wat I'm looking for?
-Thanks
Edit -
I see now that I can add a folder to the "web" directory using File Station, and then add files to that folder and access them in my web browser by going to:
/folder/filename.pdf - (although if I right click it and say open in new tab it access it through a long and convoluted url???)
which is basically what I wanted
however, I would like to be able to also go to:
/folder
and see a selectable list of all the files as well
I know I can create I link by adding something like
<a href="file.pdf" etc etc etc
to the .html file, but I'm working with about potentially thousands of files.
Is there a way to just generate one for every file in the folder.
as I'm sure you can tell I'm a noob at this.
Figured it out.
As long as you have some web server SW up and running you should be able to acces files placed in the /web folder of the "file station." for example if there is a pdf in the web folder named document.pdf you can access it by going to /document.pdf in your browser on local network.
If there is a folder name named pdf with files in it in the /web folder
you can add index.php to that folder with the following code in it to see a list of links to the files in it in your web browser.
<?php
$dir = "/volume1/web/pdf";
// Open a directory, and read its contents
if (is_dir($dir)){
if ($dh = opendir($dir)){
while (($file = readdir($dh)) !== false){
echo " <a href=./$file>$file</a><br>";
}
closedir($dh);
}
}
?>
How do I find the filename of an website I am inspecting with Firebug? As example when I look on http://example.org/ I can view inspect the Element, I see the whole html structure but I didn`t find the filename. I am searching for index.html or something in that way. Maybe this is an analog question, but I am not sure, because he/she is working with php. LINK
I know there are some solutions with Dreamweaver or other tools but I am searching for an easy way to figure that out with Firebug or an free Browser Add-On. I Hope you have a solution for that.
The URL you entered is the one that usually returns the main HTML contents. Though on most pages nowadays the HTML is altered using JavaScript. Also, pages are very often dynamically generated on the server.
So, in most cases there is no static .html file.
For what it's worth, you can see all network requests and their responses within Firebug's Net panel.
Note that the URL path doesn't necessarily reflect a file path on the server's file system. It is depending on the server configuration, where a specific URL maps to in the file system. The simplest example is the index file that is automatically called when a domain is accessed. In the case of http://example.org the server automatically loads a file index.html in the file system, for example.
So, in order to get the file name on the file system, you need to either check the server configuration or the related access logs.
I have been reading tutorials and guides concerning this but have not found a straight forward answer to this.
I currently have an existing website running on a node.js platform, locally on my computer.
Goal: Now I want to try and write a simple hello world in Dart, export it to plain JavaScript and see it work in my existing website.
Reading the documents, I read that I should create a new "Web Application" and to create some sample code up and running, I check the "Generate sample content" box.
And my project is now created in Dart Editor:
I can run the sample in Dartium, see it work, etc.
But the problem is that I have now a .html file in the Dart-project, while I have a real .html file for my existing node website in a totally different path. I don't want that. I want to try and use the existing .html instead, since.. thats my real website.
But when trying to create a new Dartium launcher, I can only refer to .html files within my Dart-project:
So my big question is; How do actually start using Dart with my existing developed website?
How do I create that bridge?
On the second image above in your original question, there is an option just below the HTML file, called URL - is this what you're looking for? You can set that to any arbitrary URL.
You'd also need to copy the helloworld.dart file into your node.js server path, and copy the bits inside the <body> tag into your existing HTML page. You'll also need to copy the packages\browser\dart.js file somewhere to your node.js server, too.
If you wanted to run the JS version, you'd also need to use the editor menu option to Generate JavaScript and copy the .js files into your node.js server path.
The script tag that refers to dart.js automatically detects if the browser supports Dart natively, and will either load the .dart version of your app, or the .dart.js version of your app (from the same folder location).
So what you're likely after is something like:
c:/nodejs_server_root
/existingIndex.html // containing the two script tags from helloworld.html
// and other tags referred to in helloworld.dart
/helloworld.dart
/dart.js
/helloworld.dart.js
And in the "URL" path in the launch configuration, you'd put something like http://localhost:<port>/existingIndex.html
https://pub.dartlang.org/packages/dev_compiler can compile Dart to Node.js modules with the --modules=node option.
See also https://github.com/dart-lang/dev_compiler/issues/291#issuecomment-176687849
Well, using HTML5 file handlining api we can read files with the collaboration of inpty type file. What about ready files with pat like
/images/myimage.png
etc??
Any kind of help is appreciated
Yes, if it is chrome! Play with the filesytem you will be able to do that.
The simple answer is; no. When your HTML/CSS/images/JavaScript is downloaded to the client's end you are breaking loose of the server.
Simplistic Flowchart
User requests URL in Browser (for example; www.mydomain.com/index.html)
Server reads and fetches the required file (www.mydomain.com/index.html)
index.html and it's linked resources will be downloaded to the user's browser
The user's Browser will render the HTML page
The user's Browser will only fetch the files that came with the request (images/someimages.png and stuff like scripts/jquery.js)
Explanation
The problem you are facing here is that when HTML is being rendered locally it has no link with the server anymore, thus requesting what /images/ contains file-wise is not logically comparable as it resides on the server.
Work-around
What you can do, but this will neglect the reason of the question, is to make a server-side script in JSP/PHP/ASP/etc. This script will then traverse through the directory you want. In PHP you can do this by using opendir() (http://php.net/opendir).
With a XHR/AJAX call you could request the PHP page to return the directory listing. Easiest way to do this is by using jQuery's $.post() function in combination with JSON.
Caution!
You need to keep in mind that if you use the work-around you will store a link to be visible for everyone to see what's in your online directory you request (for example http://www.mydomain.com/my_image_dirlist.php would then return a stringified list of everything (or less based on certain rules in the server-side script) inside http://www.mydomain.com/images/.
Notes
http://www.html5rocks.com/en/tutorials/file/filesystem/ (seems to work only in Chrome, but would still not be exactly what you want)
If you don't need all files from a folder, but only those files that have been downloaded to your browser's cache in the URL request; you could try to search online for accessing browser cache (downloaded files) of the currently loaded page. Or make something like a DOM-walker and CSS reader (regex?) to see where all file-relations are.
I can already do this with Nokogiri of course
doc = Nokogiri::HTML(src)
where src is a text column in my database.
But I really like Watir's search interface for developers over Nokogiri.
There's not much evidence on how to do this so far in my searches on the internet, viz. for unhosted html.
You can access local html files by adding a "file://" to the start of the path to the file (see my blog post on the topic).
For example, lets say you have an html file on your computer at "C:\users\testuser\desktop\test_file.html".
If you want to open this file and interact with it using Watir, you can do:
browser = Watir::Browser.new
browser.goto('file://C:\users\testuser\desktop\test_file.html')
Then you can interact with the browser/page/html as you normally would with Watir.
Note: If you get a NoMethodError: unknown property or method: 'document' exception when trying to interact with the browser, make sure that your browser is being opened by a user with administrative privileges.
If the above does not work for you, you can try navigating with the driver directly like so:
browser = Watir::Browser.new
browser.driver.navigate.to('file://Users/path/to/file.html')
PS I am on a mac, but this should work irrespective of your OS