I am making a webpage. I have to give link of a log file which is present on the server but that file is generated with a random number at the end.
I know the starting part of the filename. Here is my code -
Download log file Here
for example the name of the file is "log_parser2088.log" this 2088 number is randomly generated everytime the code runs and there is only one file in that folder which starts with the name "log_parser". I want to give reference to this file but this is not working.
HTML doesn't support this kind of references. Use PHP or ASP.NET for this task since these server side programms have access to the servers file system and can, f.e., read every filename in a directory.
Example for PHP:
// path to your log file directory
$directoryPath = "\\home\\logs\\";
// read all files from that directory
$files = scandir($directoryPath);
// print download link
foreach($path in $files)
echo("Download");
Related
How can I save two files with the same file name in the same folder without renaming anyone using php?
For instance: A user has an audio file name "first.mp3"; and another user uploads another file named: "first.mp3"; and I want to save these two files without renaming any so that when people are downloading the audio from the front end, the name does not change.
I can do this by concatenating a random number to differentiate the files but I want to beat this method of renaming.
Should I be saving each file inside a unique folder and save the file names to database? but this method will create too many folders which i don't think it is appropriate.
You cannot have two files with the same name in the same folder.
You would either have to add a random string to the end of each file like you suggest or save each user's files in a directory allocated to their account.
Regards,
Leslie
Saving multiple files with the same name within the same folder is just not possible.
I'd opt for a strategy that would involve saving the original filename somewhere (in a database, for example) along with the name/path of the actual file. When the User downloads the file (presumably through a web app of some sorts), you can set the name of the file via headers with your language of choice.
You could even rename the files to something completely random when they're uploaded so you can have them all in one folder - as long as you store the original filename somewhere, you can always set it before you serve it back to the end user.
I created a new Azure WebJobs project which is a console app. I placed a settings.json file in the root and I'm trying to access it using the following code but I keep getting an error that says it cannot locate the file. I think it's looking for it under Debug folder but I don't want to move the file there. How do I reference that file?
var config = new Configuration();
config.AddJsonFile("settings.json");
I tried "~/settings.json" but that didn't work either.
You need to identify if it's a deployment or runtime issue, per this article.
Make sure that your file is in fact getting deployed:
In VS, check that it has Copy to Output directory set to Copy if Newer
Use Kudu Console to look at the relevant WebJob folder under D:\home\site\wwwroot\App_Data\jobs\... and make sure that the json file made it to there next to the exe.
You can try to add your json file into your WebJob project's Resources as shown:
Remember to set the file type as Text and encoding to UTF-8.
In your code, you can easily access your json file as string as below:
// The Resources property depends on your actual file name being referenced
var settingsJson = Resources.settings;
Hope this helps!
currently in my test scripts for automated file upload to browser, the paths are already defined in the value column
command type
target //input[#type='file']
value /Users/.../.../.../filename.extension
in such cases, this script is unable to run on other computers because the path would be different.
my question will be is
is there a way to locate the file in a general folder (for example file is downloaded and in the "download" folder), by using selenium ide can we get the path of the file (/Users/.../downloads/filename.extension)
store the path of the file with its extension into a notepad which i will be using it for multiple test of file uploads later on.
right now if my colleague needs to run the script from his computer, he have to manually change the value to his path.
You could use a suite file that contains a "setup" file to only change the file name in 1 place and the variable is shared across tests in the suite. You could also select an agreed up on place to store the files: c:\test_info\image.jpg.
Or you can make the file available by URL & not local, Unfortunately javascript prevents that for security: How to get the current file path in javascript
Unfortunately I can't think of any other good way unless you all have the same path in a home directory and could do something like ~/test_dir/photo.jpg
this is my html code to make user to download a file and it is hitting controller
window.location.href="#routes.ListManagementController.downloadList("+listName+")?listname="+listName;
this is my controller code:
String listName = Form.form().bindFromRequest().get("listname");
response().setContentType("application/x-download");
response().setHeader("Content-disposition", "attachment;filename="+listName+"_data_export.csv");
The above two respose() statements make a pop up to download a file I want the browsed file location
File file = new File("C:/csv/" + filename);
So, using servlet api we can write the content into browsed file location using respose.getOutputStream() method. In play there are is no support for servlet. I want browsed file location selected by user so that i can give that location to File and write the file over there.
You can't get the location of a directory on the client, and even if you could, your server side could wouldn't be able to write to it (since it would usually be on a different computer).
I have seen a few examples with link to folder but i realy don't understant what it is or how to manipulate it or get it to set the specific html page within the folder.
My website is a basic one with only CSS and HTML
it is formatted as
[file]home.html // C:/Users/user/Desktop/mywebsite/home.html
[folder]Order // C:/Users/user/Desktop/mywebsite/order/
↳[file]ordersheet.html // C:/Users/user/Desktop/mywebsite/order/ordersheet.html
I want to try set the folder path C:/Users/user/Desktop/mywebsite/order/ as the file ordersheet.html C:/Users/user/Desktop/mywebsite/order/ordersheet.html how can this be done?
To set /order to ordersheet.html change the name of ordersheet.html to index.html
The index.html is the default file that the server will serve to the visitor when he visits that specific directory.
link text
link text = what you want it to say to the user
/Users/user/Desktop/mywebsite/order/ = directory path
Keep in mind that this will only work locally. If you have it up on a server, visitors don't have access to your full C:/ drive so you have to use relative links, i.e. just /order/
If I remebember correctly, you use something like this:
<a href="file:///C:/Users/user/Desktop/mywebsite/order/ordersheet.html>link to file on harddisk</a>
If you would want to have that anchor to a folder, you would just use this:
<a href="file:///C:/Users/user/Desktop/mywebsite/order/>link to a folder on harddisk</a>
Your browser is operating directly on your system's local filesystem, so you can't.
What you have been looking at is a function of a web server (I'll use Apache HTTPD for examples here).
A typical configuration of a web server would map the local part of the URI onto a directory on the local file system and just serve up the files there if they matched the local part of the URI.
If the local part resolves to a directory (rather than a file) then it would look for a file in that directory with a name that matched a list (typically including index.html) and serve up that file.
If none of the files on the list existed, then it would generate an HTML document containing links to all the files in the directory.
Since there is no web server involved when the browser is reading the local file system directly, there is no way to map the directory onto an index file, so you would need to explicitly include the filename in the URI (or switch to using a web server).