I'm creating a website that generates a text file. I would like for the user to save the file to a specific folder (it's a backup file for a video game).
Is it possible to change the default folder the file is saved to via PHP or HTML? C#, while not my first pick, would also be acceptable.
If I understand correctly, NO you cannot default to a location on the users computer. This is just a security piece that you cannot get around.
Try educating the user before they download. That's the best way.
No file download locations are handle at the browser level
You could probably package the text file in an installer / extractor that loads it to the location you want, but I don't think you want to go that far ^.^
You cannot prompt the user to save the file to a specific place on his/her computer, you can however save some stuff on the users pc by the use of Web Storage, that is a part of the HTML5 spec. You will not be able to control where it will be saved though.
It would not be a smart move to store backups for your game on the users pc, as it would open a endless world of cheating and hacking.
Related
I'm facing a dilemma on how to implement file upload and download in a PHP website.
I have these criteria:
Performance - does not give performance issues to the website
File size - around 2GB and up.
Authorization - I want to be able to change who can access the files in PHP. Allow multiple users to gain access to a single file.
User friendly - no additional tools to use.
So here are the methods I'm currently looking at and how I assess them based on my criteria:
Database BLOB
Writing the file data into the output stream will take time and blocks other requests (is this correct?)
I read somewhere that there's a size limit for BLOB.
OK - I can easily control who can download the files here.
OK - No additional tools, just the website.
FTP
OK - since it is designed to store files.
OK - file system is the limit.
I need to create another credentials for each user aside from the username and password for the website. I assume I have to move the file from one location to another to update authorization, but how if multiple users can access one file? Shared directory? It looks messy.
Need another tools/program for accesing their files, need to remember another username and password.
My questions:
Based on my assumptions, do you thimk I understand the methods correctly?
If my assumptions are wrong, is there a way I can do this functionality while meeting my criteria?
PS Please excuse my English.
Why not just use the file system to store the files and store the path to the given file (+ permissions, if needed) in addition in a database.
The upload folder isn't accessible from the public and an wrapper script serves the content to the user.
Performance shouldn't be a problem as you just move/copy the uploaded file to a dedicated data directory.
File size isn't a problem (as long, as you have enough disk space)
The wrapper script handles permissions and serves files to the users
It's as friendly, as you design your ui
for me the usage of BLOB is not the best. I thought about BLOB to upload pictures in my own website, but the best way to upload file is to put them directly on ur server locally.
Is there a possibility to preselect a local path when downloading a file via php script ?
What I mean is, if I download a file, the browser prompts a window to select download location, if there was no permanently path set. Since there are many OS out there with different fileroots which structure I don't know, I wanted to give the user of my webapplication the possibility to save the savepath to a database. And if he starts a export and file is getting downloaded that the path were the file goes is presetted. Is this possible ? Sorry for my english :D
I searched google without results... may im looking wrong ^^
It is not possible because of security issues. You cannot access users' filesystem via browser without their knowledge - A user has to pick a file/directory/path to save something by their own.
I am writing a scripts that processes the .csv file. The script currently have to upload the csv file to the server in order to process it, and the user have to download the processed file which is a lot of work from a user.
My question is, is there a way to process files from the user's directory path without the user having to upload the file first? So the user will just browse to the file to be processed and the file will be save and processed in that path.
Thanks,
Sbo
Then the only option you have is to do it client-side. To do it client-side you thus have to use a client-side technology like Flash or JavaScript. The latter is probably the better choice. The following URL explains how you can do a client-side file upload: http://igstan.ro/posts/2009-01-11-ajax-file-upload-with-pure-javascript.html
You want to get access to user's computer? Forget it.
Only way to achieve it is to use Java Applets with special permissions in php you need to upload it, it can be uploaded to temp directory but you need to still upload it.
Java Applets need to be signed and has certificate to be accepted by user. There is no other way I know to get access to user's files.
Check this link as well
In my website, the user can upload a profile image. The website structure is as follows:
C:\xampp\htdocs
C:\xampp\upload\user1
For security reason, the upload file has been moved into folder C:\xampp\upload\user1\.
The question is how I can serve this image later to the user. In other words, after uploading the image, the user should be able to see the upload image on the web page. What should I do?
Here is what I can figure out
Introduce a new folder C:\xampp\htdocs\picture\randomimagename
which is used to temporarily save the user's picture.
Use the link to C:\xampp\htdocs\picture\randomimagename and serve it to the user.
Now the problem is when should I delete this image?
when the user logouts out. yes, I know how to do this.
when the user closes the browser. how do I know this?
any other cases.
Save the image to C:\xampp\htdocs\picture\randomimagename and then every once in a while, have a Windows Scheduled Task clean it out (e.g. when it's been more than 15 minutes since it was created).
That way you don't have to worry about doing it when the user logs out, or when the user closes the browser, or anything else. Tweak how frequently the job runs depending on how much you care about disk space vs how much you care about CPU usage/IO.
By the way, I hope you're not doing things like:
<img src="C:\xampp\htdocs\picture\randomimagename.jpg" />
that will only work when run on the server which Apache is running on. You want to use a proper path, relative to your site's root.
I have created a website.In that scaling an image option is created.. Now i want to store that scaled image in users desktop..But its saving in code existing folder..
Please help me by sending php script to store that file in desktop
If your website is going to actually live on the web instead of on people's computers locally then you can't directly save it to their computer. You can serve it to them with php as a file download by setting the proper mime-type and content headers (using header()) followed by the file itself, or better yet offer the user a download link so they can choose to download it themselves.
If your website is going to be used locally (a little odd, but it could happen), then you can use fopen(), fwrite() and fclose() in php to work with local files.
I don't think it is possible to do this without asking for user intervention on where to save the processed file. If you think about it, it would be a significant security flaw if a web server could arbitrarily save files to user desktops!
The best you could do is set the content header of the generated file to have a content disposition of attachment and then the browser will prompt the user where to save the file.