How to store processed file in users desktop? - php

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.

Related

php - how to use readdfile to not force a download

Is there a way to use php readdfile function to allow browsers to stream media files, such as an mp3 file?
I currently have a download system where readdfile is used because the file downloads are not stored in a public directory, however, I would like my users to be able to stream these files with there browser. At the moment, it forces them to download.
I have used the example from php.net.
thanks,
josh.
Depends on what the files are, and what you mean by "stream". The proper definition, in this context, is to send out enough of a large audio or video file that it can be played clientside without having to have received the entire file. Also, most streaming service allow the user to 'seek' to any given position in the video and have the stream restart at that point, again so that the user does not have to download the whole file.
The above requires specialized streaming server software.
However, I get the feeling that you may simply want the browser to open the file instead of prompting the user to save it. This requires you to set the Content-Type: header with the proper MIME type to the client via the header() function.

Processing file in the users directory

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

Prompt user to save file to a specific location

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.

PHP Download resume with hidden url link for large file

I'm sorry to bother you with my issues, but i'm facing a a problem that I have some trouble to fix.
I have a website with a login restricted area.
Once the user is logged he can access to the files of my company (big file)
But to avoid the link to be spread all over the internet when a user want to download the file, located on an external url: he clicks on a url which will contain the name of the file crypted in md5 , which redirect on a php script which is going to generate in php, headers with the download using fsockopen.
However this does not support resume of download which is not very practical when we are downloading somes files of 2 or 3 gb or when you are using a downloader.
How can I do to enable resume ?
I have seen some php scripts using fread method , however i don't think it would be a good idea in my case, because for big files, it could make lag the server.. when you do a progressive fread on a 2gb files, good luck for the process when they are 30 poeple downloading the file in the meantime.
If you use fopen() and fseek() like this, you're essentially doing the same as any Webserver does to reply HTTP-RANGE requests.
You could make it so that it doesn't allow the file to be downloaded unless they are logged in.
So instead of providing them with a direct link to the file, they get a link like foo.com/download.php?myfile.ext
And the download.php would check the session before providing the user with the file download.

save the file in users desktop

I have a file where i m able to generate the pdf, but i want the path to be users desktop which would save it automatically.
$pdf->Output("sample.pdf");
What should be path.
No matter what you have server side you won't be able to automatically save a file on a user's system via their browser with no interaction from them as that would be a massive security hole. The user will always have to confirm the save of a file.
For similar reasons you won't be able to query the directory structure of a User's system via the browser, and even if you could I don't think you can give a browser a suggested directory in which to save something.
You can't do that with PHP. PHP runs on your server, not on your user's desktop. You probably want to store the file somewhere on the server, and then show the user a link to download the generated file.
Unless of course, you're talking about running PHP locally on your user's computer (i.e. apache or some other webserver is installed on your user's computer, in which case please clarify your question.
Assuming your php script is running as a client-side app through the Command Line Interface or PHP-GTK, you should first check if the system it runs on actually is a Win32 type machine.
Next you'd need to use the Windows Only Extensions to invoke the native Win32 API Function call returning a well-known location such as user's desktop folder, that is SHGetFolderPath() with a CSIDL_DESKTOP as a second parameter.
If however your script runs on a server, there's no way to put the file on user's desktop directly without her actually being instructed to do so.
You should output the PDF to the browser and provide the appropriate headers to have the file be recognised as PDF (or merely as downloadable to force a download). Also make sure not to output anything other than the PDF as that might corrupt the file.
EDIT: Note that if you use a webbrowser it is, for security reasons, not possible to FORCE an automatic download. You can only prompt a download, not activate it.
If you're talking about a PHP script (e.g. on a Linux workstation), you probably want to do something completely different. If the PDF library doesn't let you specify a path, do the same you would do in a web browser sans the headers and use an output buffer to catch the output and write it to a file -- if you run the script directly, it'll have the necessary privileges to write to your home directory.

Categories