witham Posted June 4, 2010 Share Posted June 4, 2010 Hi I have written an upload script that restricts users from uploading anything other than pdf documents. After the php handles the upload and sends it to the directory I would really like to show a preview of the pdf that was uploaded. I have searched through the php.net website and have got really confused as to which pdf function to call. I assumed it would simply be PDF_open_file?? but I can't seem to get it to work. Before I continue it would be great to be certain that I am using the correct function. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/203867-displaying-pdf/ Share on other sites More sharing options...
Alex Posted June 4, 2010 Share Posted June 4, 2010 You mean like create a thumbnail of the pdf? This can be done with imagemagick, if you have it installed. Quote Link to comment https://forums.phpfreaks.com/topic/203867-displaying-pdf/#findComment-1067732 Share on other sites More sharing options...
witham Posted June 4, 2010 Author Share Posted June 4, 2010 Hi thanks for your replay. All I really need to do is display the pdf in the browser after the upload. Quote Link to comment https://forums.phpfreaks.com/topic/203867-displaying-pdf/#findComment-1067738 Share on other sites More sharing options...
Alex Posted June 4, 2010 Share Posted June 4, 2010 You mean like redirect them to it after upload? Post your code so we can help you. Quote Link to comment https://forums.phpfreaks.com/topic/203867-displaying-pdf/#findComment-1067739 Share on other sites More sharing options...
witham Posted June 4, 2010 Author Share Posted June 4, 2010 Thanks <html> <head> <title>Uploading...</title> </head> <body> <h1>Uploading file...</h1> <?php if ($_FILES['userfile']['error'] > 0) { echo 'Problem: '; switch ($_FILES['userfile']['error']) { case 1: echo 'File exceeded upload_max_filesize'; break; case 2: echo 'File exceeded max_file_size'; break; case 3: echo 'File only partially uploaded'; break; case 4: echo 'No file uploaded'; break; } exit; } // Does the file have the right MIME type? if ($_FILES['userfile']['type'] != 'application/pdf') { echo 'Problem: file is not pdf text'; exit; } // put the file where we'd like it $upfile = 'C:/uploads/'.$_FILES['userfile']['name']; if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { if (!move_uploaded_file($_FILES['userfile']['tmp_name'], $upfile)) { echo 'Problem: Could not move file to destination directory'; exit; } } else { echo 'Problem: Possible file upload attack. Filename: '; echo $_FILES['userfile']['name']; exit; } echo 'File uploaded successfully<br><br>'; // reformat the file contents $contents = strip_tags($contents); $fp = PDF_open_file($upfile, 'w'); fwrite($fp, $contents); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/203867-displaying-pdf/#findComment-1067749 Share on other sites More sharing options...
witham Posted June 5, 2010 Author Share Posted June 5, 2010 Problem solved!! After much more digging and reading I managed to do this by including header('Content-Type: application/pdf'); at the very top of the script and to display the file // Display uploaded.pdf readfile($upfile); as the last function call. Thanks anyway I hope this helps someone else!! Quote Link to comment https://forums.phpfreaks.com/topic/203867-displaying-pdf/#findComment-1068218 Share on other sites More sharing options...
Mchl Posted June 5, 2010 Share Posted June 5, 2010 Seriously that much digging and reading? Isn't it given as an example in manual entry for header? Quote Link to comment https://forums.phpfreaks.com/topic/203867-displaying-pdf/#findComment-1068231 Share on other sites More sharing options...
jskywalker Posted June 5, 2010 Share Posted June 5, 2010 http://lmgtfy.com/?q=how+to+show+PDF+from+PHP&l=1 because he obviously did not know about the 'header()' function.... Quote Link to comment https://forums.phpfreaks.com/topic/203867-displaying-pdf/#findComment-1068234 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.