How do I link to a PDF file in Silex? - silex

I've looked around a bit and can't seem to figure out how to link to a static file while using Silex. I've seen some similar questions/answers in regards to Symfony, but they involved YML routing files, which I don't use with Silex.
My Situation
I have some files in a /docs folder. Logged in users can upload new pdf files (so, I don't know ahead of time what all of the filenames will be; they're constantly changing).
My Intent
I need to be able to link to these PDF files, so that a click on a link somewhere will open www.myurl.com/docs/myfile.pdf.
The Problem
Due to the routing system in silex, it treats the url as a route (obviously) and throws a Page Not Found error.
Thanks in advance for any feedback!

You need to configure your web server in a way that it does not forward existing files to the front controller. The web servers section of the silex documentation has examples of such configurations for the most popular web servers.
As for the link itself, just link to the file directly, something along these lines:
{{ filename }}

Related

I want to produce Link with a path for sharing limages

I have a folder which have a construction below.
images_folder1/
├image01.png
├image02.png
images_folder2/
├image01.png
├image02.png
I want to upload these folders and get the link to access and I hope that the link has something like a relative path or absolute path.
(ex: https://〇〇//images_folder1/image01.png)
I already tried to use Github to accomplish this goal. Actually Github enables me to get the link with a path structure like "https://github.com/User/test_repo/blob/main/images_folder1/image01.png".
but the images should not be seen to other people except for those who know the link.(Github's private repository cannot do this. I have to get the repository "public") That's why Github is not suitable.
Also, I came up with the idea to get the link by using online storage services like "Box" but the link that I can get via Box seemed to be encrypted.(I mean there are no relationship between the folder structure and the link itself.)
Are there anyone who know the best websites or applications suitable for my requirements?
It is the first time to ask questions via stack overflow and I'm Japanese, so there might be some expressions hard to understand or sentences that don't contain sufficient explanations. Please let me know.
GitHub also gives you a relative or absolute path for your image other than url like https://github.com/User/test_repo/blob/main/images_folder1/image01.png. Just make sure, the url path you have given is correct. As:
If your GitHub pages site is publised at abc.github.io then type abc.github.io/images_folder1/image01.png.
If your GitHub pages site is publised at abc.github.io/repository then type abc.github.io/repository/images_folder1/image01.png.
Note: Make sure that no "/" is used at the end of the image, or page, url. Such that abc.github.io/images_folder1/image01.png/ should not be used instead of "abc.github.io/images_folder1/image01.png" , otherwise it will throw an error.
EDIT:
Suppose your GitHub username is "abc".
And you create a repository named "tiger", and turn GitHub pages on from the setting.(If your repository is private then you will need to upgrade to a premium account to active GitHub Pages)
Then your GitHub Pages will be published at "https://abc.github.io/tiger",i.e.,
("https://your-username.github.io/repository-name") by default and the "index.html" file will work as your homepage.
And if you repository name is "tiger.github.io" instead of only tiger, then your GitHub Pages will be published at "https://tiger.github.io",i.e.,
("https://repository-name.github.io").
But of you want to connect it to a custom top-level domain then you can do it from the settings.

Change domain without 404 error code?

I have changed all the URLs of my website. (Domain is the same. For example: http://www.example.com/category/sample ----> http://www.example.com/Category/Sample)
Now it seems to have lots of 404 pages that are effecting my SEO.
What should I do to solve this problem? Any suggestion?
Thank you
You can proceed with changing the Context root for your website. Context roots determine the URL of any web-application.
Click here for a short article for making changes to context-roots.
The process may change based on the Server you are using.
Just create sitemap.xml file. There are many online sites available that will create free sitemap.xml file. Just you have to submit your website url and within few seconds they will generate sitemap.xml file. Download this sitemap.xml file and place it into your root directory. When crawler run through your website it will automatically update your all links and within few days you will see all updated links are present in search resulting page like google search engine.
Note: Also, dont forget to update sitemap.xml file path in robot.txt file.

What is the best practice to publish online the /doc folder

I am using Rails (4.1.5) and I have generated a full documentation which has been put in /doc as by default. My app is publish online but internally. I would like to expose this documentation through an URL part of my actual (e.g. http://myapp.com/doc). I want to find a way to automate this as the "generate the doc" action will be done on my side to refresh the documentation.
Somebody have any idea what should be the trick for this? Route (if so, how), should I create a controller for that specifically?
Thank you in advance for any help on this.
I've done this using Dropbox. I run my documentation generator command and have it output to a location in my Dropbox folder. Then, my colleagues can simply open the index.html file at the shared location to view the documentation. But, in your case I suppose you could have your myapp.com/doc url redirect to the dropbox location? The advantage of all this being that you don't have to redeploy to have updated documentation -- just regenerate the docs since Dropbox does the uploading and hosting for you.

Show files on FTP in a Rails App

We have an FTP site for clients, and they just go to it with a web browser and see the files. I'd like to display the files in a more visually pleasing manner, is there a way I can show what files are on the server in the view, perhaps iterate over them and style them?
I found this answer here, but really didn't answer my question:
Ruby-Rails serve ftp file direct to client
(using rails 3 if it makes a difference)
You can use library links below:
http://www.ruby-doc.org/stdlib-1.9.3/libdoc/net/ftp/rdoc/index.html
http://oreilly.com/catalog/ruby/chapter/ch04.html
and you can use EventMachine https://github.com/schleyfox/em-ftp-client.
Cheers!

How To Dynamically Route to Downloads

Basically, this is what my app does:
It sends an AJAX request
The server creates a file
The server sends back the URL of the
file location
The client-side will attempt to
create a dialog to download the file
at that location (probably using a
frame? I haven't got this far yet).
My question is, how do I dynamically route to the files I create so that they are accessible when you browse to them? If I don't add a route for them, then they will get a 404 if they try and access the directory they're in.
The files are currently stored in a folder in public.
Would the best way to deal with this make the folder somehow not require a route, so that it can be browsed to directly, and then have an index page on it so they can't view the full list of files? If so, please let me know how I can accomplish this. And on a side note, if you have an idea of how I can accomplish JS displaying the download dialog let me know.
It's Rails 3 by the way.
Thanks!
For a full private set of files: choose a place for your files outside your public directory, then configure X-SendFile support in your web server and finally use send_file in your rails application.

Resources