FishSword Posted May 2, 2011 Share Posted May 2, 2011 Hiya, I’m currently working on a website that will enable users to upload certain types of files. Upon the file(s) being uploaded, I need to generate a preview of the file(s) content, in image format. Some of the files I need to upload and generate a preview of include, but are not limited to: .doc(x), .jpg, .ppt(x), .xls(x), .html, .psd. Can this be done with PHP? Any help is greatly appreciated. If you have any queries, please let me know. Many Thanks, FishSword Quote Link to comment https://forums.phpfreaks.com/topic/235371-preview-uploaded-files/ Share on other sites More sharing options...
fugix Posted May 2, 2011 Share Posted May 2, 2011 you could use file_get_contents to grab the file contents of the file that you want an image for...then using the various image functions found here you can convert the text into an image for viewers to see Quote Link to comment https://forums.phpfreaks.com/topic/235371-preview-uploaded-files/#findComment-1209546 Share on other sites More sharing options...
FishSword Posted May 2, 2011 Author Share Posted May 2, 2011 Hi Fugix, Thanks for your reply. I think you may have got confused when I said that I need to display the contents of a file in image format. I don't want to display the code/text that makes up the file as an image, but instead show the actual content that the code represents, as an image. For example, if somebody uploaded a Microsoft Word file containing a letter addressed to somebody, then the preview that should be generated, would be of the letter. I have attached a screenshot showing the preview generated for a file when a file has been selected in Windows Explorer. I am after a preview of a file, similar to this. I appreciate your help Many Thanks, FishSword [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/235371-preview-uploaded-files/#findComment-1209642 Share on other sites More sharing options...
fugix Posted May 2, 2011 Share Posted May 2, 2011 Sorry. I did misunderstand you. I will have to look into how to do this correctly. Quote Link to comment https://forums.phpfreaks.com/topic/235371-preview-uploaded-files/#findComment-1209666 Share on other sites More sharing options...
FishSword Posted May 3, 2011 Author Share Posted May 3, 2011 No Problem! Cool. Quote Link to comment https://forums.phpfreaks.com/topic/235371-preview-uploaded-files/#findComment-1209766 Share on other sites More sharing options...
gizmola Posted May 3, 2011 Share Posted May 3, 2011 Hey FishSword, There are libraries out there that can do some of the files you're talking about but not all, and of course there is an issue with versions of those files and the many formats over the years when you're talking about the microsoft suite. I know some things about doing this, and I can tell you that it is not a trivial task, and very much related to the operating system of the machine(s) used to render the thumbnail image. Here's a couple approaches you can consider: -Based on the extension of the file, load a program that can process the native file format. Then print that to pdf and use imagemagick or some other program that can convert .pdf's to images. Then resize to thumbnail. -Based on the extension of the file, load a program that can process the native file format and put the application into full screen mode, then call an operating system macro that can capture the framebuffer/printscreen the page to an image, and then thumbnail the image. Quote Link to comment https://forums.phpfreaks.com/topic/235371-preview-uploaded-files/#findComment-1209776 Share on other sites More sharing options...
FishSword Posted May 3, 2011 Author Share Posted May 3, 2011 Hi Gizmola, Thanks for your reply. When you say program, would this need to be a program that is installed within the operating system? Would it not be possible to achieve this using PHP, or through the development of a library file, that could be plugged into to PHP? My aim is to take screenshots of the files, and save these screenshots in image format. Thanks for your help so far, its a very interesting topic. Many Thanks, FishSword Quote Link to comment https://forums.phpfreaks.com/topic/235371-preview-uploaded-files/#findComment-1210027 Share on other sites More sharing options...
gizmola Posted May 3, 2011 Share Posted May 3, 2011 Yes you literally need at least one program that can handle every file format you're talking about, and be able to render them. For a lot of the image files, there are libraries that will let you load and manipulate them, but for word docs, excel spreadsheets and powerpoints. If your focus is these microsoft application formats, then a windows machine has a lot of advantages due to the windows os technologies used. I have my doubts about being able to prtscrn everything, but you definately can have a custom print driver installed like the one that comes with adobe pdf. Quote Link to comment https://forums.phpfreaks.com/topic/235371-preview-uploaded-files/#findComment-1210056 Share on other sites More sharing options...
FishSword Posted May 7, 2011 Author Share Posted May 7, 2011 Hi Gizmola, Thanks for your reply. I would prefer to use Apache server to host the site, on a Linux machine. I've heard that it is possible to develop extensions for PHP. How easy would it be to build such an extension that would generate preview images of files, and can this be done? Many Thanks, FishSword Quote Link to comment https://forums.phpfreaks.com/topic/235371-preview-uploaded-files/#findComment-1211956 Share on other sites More sharing options...
gizmola Posted May 7, 2011 Share Posted May 7, 2011 If you know C very well you can probably develop a php extension. Being on linux, I'd take a look at open office which is written in java, and see if that might not make a good basis for a lot of this system, since open office can load in a lot of the microsoft files. Quote Link to comment https://forums.phpfreaks.com/topic/235371-preview-uploaded-files/#findComment-1212031 Share on other sites More sharing options...
FishSword Posted May 8, 2011 Author Share Posted May 8, 2011 Do you need to use OpenOffice? Can this be done achieved through the development of just a php extension? Having the generated file previews coded completely as an extension will provide more control over the outcome. Quote Link to comment https://forums.phpfreaks.com/topic/235371-preview-uploaded-files/#findComment-1212467 Share on other sites More sharing options...
gizmola Posted May 9, 2011 Share Posted May 9, 2011 I would say that loading, rendering and saving rendered output to some sort of image file that reflects what a print view of excel, word and powerpoint documents is what I would consider a "non-trivial" task to say the least. Anything is "possible", but I don't know of any open source libraries you could use other than open office. It is conceptually possible to call java routines using the java bridge, but I have no idea if that's a viable path. Hopefully I've provided you a few ideas to explore. Quote Link to comment https://forums.phpfreaks.com/topic/235371-preview-uploaded-files/#findComment-1212724 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.