Download file from database using php and ajax






















Notify me of new posts by email. Post Comment. Begin typing your search term above and press enter to search. Press ESC to cancel. September 1, Bikash January 19, March 21, Let's do that now. Create a new database called file-management. Under this database, create a table called files and give it the following fields.

Now open index. You can always configure this info in your php. Having selected your file, you can click on the upload button. If everything goes well, your file will be uploaded to the uploads folder in your project and a new record will be created in the files table in the database containing the filename, size, and downloads count. Now our file has been uploaded. You can check your uploads folder and database table to confirm that it was successful. Let's display it so that the user can view it and click on it to download it.

First, we need to fetch the file info from the database. Good Generic Code. Thanks leo. Its helpful. Also what do you suggest adding window. The filename will be wrong if the content disposition specifies a non-UTF8 filename. So, after I get the responseText and everything is Ok, I redirect browser like this: window.

Pedro Sousa Pedro Sousa 6 6 silver badges 11 11 bronze badges. Isn't this dangerous security-wise? I would think so because anybody can call download. Since the access has reached a PHP script, htaccess now stops its duty. One should always sanitise the requested file to be read — Prof. Show 2 more comments. I prefer location. Telmo Dias Telmo Dias 3, 2 2 gold badges 31 31 silver badges 42 42 bronze badges.

Alain Cruz Alain Cruz 3, 3 3 gold badges 19 19 silver badges 37 37 bronze badges. Jemil Oyebisi Jemil Oyebisi 7 7 silver badges 8 8 bronze badges.

Decoding a filename from the header is a little bit more complex Jaime 4, 2 2 gold badges 19 19 silver badges 42 42 bronze badges. Lumic Lumic 41 2 2 bronze badges. Please format your entire code block and provide some additional explanation to your process for future reader benefit. You can just make the a tag hidden and populate the href dynamically. First you need to separate the page processing from the results download.

For example, this can be a page that prints the results of a table calculated in the ajax call. I hope this solution can be useful for many, as it was for me. Ryan Dooley Ryan Dooley 3 3 silver badges 14 14 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Please Sign up or sign in to vote. See more: PHP.

I am required to download different type of files from a spesicif folder using ajax. The problem is that when execute the code I I get this message [ here ] I have looked for the similar tutorials I coundnt find a solution Could you please help What I have tried: This my index. Copy Code. Posted 5-Oct am Member Updated 9-Oct am Kornfeld Eliyahu Peter. Add a Solution. Richard MacCutchan 6-Oct am. And you think that we can guess what message and where it occurs?

You have updated the question, but we still have no idea what message or where it occurs. Accept Solution Reject Solution. Posted 9-Oct am Richard Deeming.



0コメント

  • 1000 / 1000