PHP - Upload Word Document
Hello, I had created a form for users to upload their resumes (only word documents & 1 MB allowed as size), then email it after its been successfully uploaded. Any help? Thanks in advance Similar TutorialsI am running PHP 5 on a linux server. I want to be able to open a .doc or .docx file with PHP (or any way possible, for that matter) in order to grab the contents from it. How can i do this? I know COM classes work with windows for this, but i have linux. Any ideas are greatly appreciated. Thanks. This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=316747.0 so I want to know how I could upload a document associated with an event.......with a form upload.......but where do I store it at and make it display in the view page for the event......? how do I make document upload fields like the ones that are on this website where there is a link at the bottom to make another field appear, or make it so that a new field automatically appears when the first one has info in it. Does this make sense? and also how would i make these submit with the form seeing as that they would have different field names, wouldn't they? Hi everyone. I have been looking for a PHP upload script that handles various different document types like PDF, DOC and XLS. So far all I have found is image upload scripts. Can anyone point me in the right direction? I would be most greatful. Thank you! This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=334078.0 Hi guys, I have created a php script (with alot of help from others) that allows me to have a login area on my website. When the user logs onto their page - they obviously cannot see the others profile. My next task is to be able to upload PDF documents to appear on their profiles. The PDF's will be specific to them. The main problems I have a 1/ They cannot be able to view any PDF but their own. 2/ How do I create a form that knows where to send and display the link? I guess it is using the user id & name etc? I will not actually be the one uploading the files else I would just sit and tediously link each form to each profile. This must be done by my secretary via a file upload form that I will password protect. I basically want her to be able to log in and be presented with a document upload form. The form will have a dropdown list of the clients name and a document upload part. From uploading it will then appear on the users page. If anyone could help it would be amazing! I am fairly new to PHP although am getting better with my understanding. Hopefully I will become as good as you lot one day! Cheers in advance I have code written for image uploading, but it doesn't allow multiple images on a single upload, and doesn't re-size. Anyone willing to share a good upload script that will do the following?: -Allow multiple image uploads (10+ per submission), -Re-size images on upload, and -Rename images. Thanks Brett Hi everyone, I have a page that i use to upload images to my website, i got a bit fed up of uploading one at a time so i decided to add multiple file fields to the form to upload multiple images at the same time. Im having a few problems, iv read up he http://www.php.net/manual/en/features.file-upload.multiple.php and it seems all i have to do is add [] to the form names to turn them into arrays. However when i come to upload the images, i keep getting the "$error[] = "Incorrect format!...." error from the code below. I cant seem to figure out what the problem is. Could anybody please point me in the right direction? <?php session_start(); $id = $_SESSION['id']; $connect = mysql_connect("localhost","leemp5_admin","p7031521"); mysql_select_db("leemp5_database"); $query = mysql_query("SELECT * FROM users WHERE id='$id'"); $row = mysql_fetch_assoc($query); $username = $row['username']; $submit = $_POST['submit']; $type = $_FILES['image']['type']; $size = $_FILES['image']['size']; $max_size = "1000"; $width = "100"; $height = "100"; $error = array(); function make_thumb($image_name,$filename,$new_width,$new_height) { $ext=getExtension($image_name); if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext)) $source_image=imagecreatefromjpeg($image_name); if(!strcmp("png",$ext)) $source_image=imagecreatefrompng($image_name); if(!strcmp("gif",$ext)) $source_image=imagecreatefromgif($image_name); $old_x=imageSX($source_image); $old_y=imageSY($source_image); $ratio1=$old_x/$new_width; $ratio2=$old_y/$new_height; if($ratio1>$ratio2) { $thumb_width=$new_width; $thumb_height=$old_y/$ratio1; } else { $thumb_height=$new_height; $thumb_width=$old_x/$ratio2; } $destination_image=ImageCreateTrueColor($thumb_width,$thumb_height); imagecopyresampled($destination_image,$source_image,0,0,0,0,$thumb_width,$thumb_height,$old_x,$old_y); if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext)) { imagejpeg($destination_image,$filename); } if(!strcmp("png",$ext)) { imagepng($destination_image,$filename); } if(!strcmp("gif",$ext)) { imagegif($destination_image,$filename); } imagedestroy($destination_image); imagedestroy($source_image); } function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } if($submit) { $image=$_FILES['image']['name']; if ($image) { $filename = stripslashes($_FILES['image']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { $error[] = "Incorrect format! Please make sure your image is a .jpg, .jpeg, .png or .gif file."; } else { $size=getimagesize($_FILES['image']['tmp_name']); $sizekb=filesize($_FILES['image']['tmp_name']); if ($sizekb > $max_size*1024) { $error[] = "Your image is too big! The maximum upload size is 1MB."; } else { $image_name=time().'.'.$extension; $newname="uploads/" . $username . "/images/".$image_name; $copied = copy($_FILES['image']['tmp_name'], $newname); if (!$copied) { $error[] = "There was an error uploading your image. Please try again!"; } else { $thumb_name='uploads/' . $username . '/images/thumbs/thumb_'.$image_name; $thumb=make_thumb($newname,$thumb_name,$width,$height); } } } } else { $error[] = "Please select an image to upload!"; } if(empty($error)) { echo "Upload Successfully!<br />"; echo '<img src="'.$thumb_name.'">'; mysql_query("INSERT INTO images VALUES ('','$username','$image_name','','','','','uploads/$username/images/$image_name','uploads/$username/images/thumbs/thumb_$image_name','$type','$size')"); } else { echo implode($error); } } ?> <form method="post" enctype="multipart/form-data" action="upload_images.php"> <input type="file" name="image[]" /><br /> <input type="file" name="image[]" /><br /> <input type="file" name="image[]" /><br /> <input type="file" name="image[]" /><br /> <input type="file" name="image[]" /><br /> <input type="file" name="image[]" /><br /> <input type="submit" name="submit" value="Upload"> </form> Thanks files that upload during insert/submit form was gone , only files upload during the update remain , is the way query for update multiple files is wrong ? $targetDir1= "folder/pda-semakan/ic/"; if(isset($_FILES['ic'])){ $fileName1 = $_FILES['ic']['name']; $targetFilePath1 = $targetDir1 . $fileName1; //$main_tmp2 = $_FILES['ic']['tmp_name']; $move2 =move_uploaded_file($_FILES["ic"]["tmp_name"], $targetFilePath1); } $targetDir2= "folder/pda-semakan/sijil_lahir/"; if(isset($_FILES['sijilkelahiran'])){ $fileName2 = $_FILES['sijilkelahiran']['name']; $targetFilePath2 = $targetDir2 . $fileName2; $move3 =move_uploaded_file($_FILES["sijilkelahiran"]["tmp_name"], $targetFilePath2); } $targetDir3= "folder/pda-semakan/sijil_spm/"; if(isset($_FILES['sijilspm'])){ $fileName3 = $_FILES['sijilspm']['name']; $targetFilePath3 = $targetDir3 . $fileName3; $move4 =move_uploaded_file($_FILES["sijilspm"]["tmp_name"], $targetFilePath3); } $query1=("UPDATE semakan_dokumen set student_id='$noMatrik', email= '$stdEmail', surat_tawaran='$fileName', ic='$fileName1',sijil_lahir='$fileName2',sijil_spm= '$fileName3' where email= '$stdEmail'");
I have this code below the browser shows correct data but when i export to word I see $proc output not the switch data like on the the browser page
How should code be written to show the same on word doc .
I'm new to this learning by trial and error Please go easy on me .
Thanks
<td> <? I'm going to post the code that I am currently using and then explain what I'm trying to do. I hope I can explain it well enough. <?php if (!isset($_POST['submit'])) { echo'<leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0"> <center><form name="fairlistlist" method="POST" action="'.$_SERVER['PHP_SELF'].'"> <TABLE width="450" height="119" border=0 cellPadding=3 cellSpacing=2 bgcolor="#fff568"> <TBODY> <TR> <TD class=mainText width="100"><b>Event Name</b></TD> <TD width="305" class=frmInput> <INPUT class=mainFormBox style="WIDTH: 320px" type="text" name=" fairname"></TD> </TR> <TR> <TD class=mainText width="100"><B>Event Address</B></TD> <TD class=frmInput> <INPUT name="fairadd" type="text" class=mainFormBox id="fairadd" style="WIDTH: 320px"></TD> </TR> <TR> <TD class=mainText width="100"><b>Event City</b></TD> <TD class=frmInput> <INPUT name="faircity" type="text" class=mainFormBox id="faircity" style="WIDTH: 320px"></TD> </TR> <TR> <TD class=mainText width="100"><b>Event County</b></TD> <TD class=frmInput> <INPUT name="faircty" type="text" class=mainFormBox id="faircty" style="WIDTH: 320px"></TD> </TR> <TR> <TD class=mainText width="100"><b>Event State</b></TD> <TD class=frmInput> <INPUT name="fairstate" type="text" class=mainFormBox id="fairstate" style="WIDTH: 320px"></TD> </TR> <TR> <TD class=mainText width="100"><b>Event Country</b></TD> <TD class=frmInput> <INPUT name="fairctry" type="text" class=mainFormBox id="fairctry" style="WIDTH: 320px"></TD> </TR> <TR> <TD class=mainText width="100"><b>Event Opening Date</b></TD> <TD class=frmInput> <INPUT name="fairopen" type="text" class=mainFormBox id="fairopen" style="WIDTH: 320px"></TD> </TR> <TR> <TD class=mainText width="100"><b>Event Closing Date</b></TD> <TD class=frmInput> <INPUT name="fairclose" type="text" class=mainFormBox id="fairlose" style="WIDTH: 320px"></TD> </TR> <TR> <TD class=mainText width="100"><b>Event Contact Email</b></TD> <TD class=frmInput> <INPUT name="fairmail" type="text" class=mainFormBox id="fairmail" style="WIDTH: 320px"></TD> </TR> <TR> <TD class=mainText width="100"><b>Event Website</b></TD> <TD class=frmInput> <INPUT name="fairweb" type="text" class=mainFormBox id="fairweb" style="WIDTH: 320px"></TD> </TR> <TR> <TD class=frmDescription width="56"> </TD> <TD class=frmInput> <div align="right"> <input type="submit" name="submit" value="Add my Event" /> </div></TD> </TR> </TBODY> </TABLE> </form></center> </body>'; //note that I added a new field called submit and it's hidden .. } else { /*I added addslashes() so it escape any special char in the form .. if you want to show your inserted record , you need to use stripslashes() to remove any slashes from the record .. this is only to avoid some security problems in the query ..*/ $fairname=trim(addslashes($_POST['fairname'])); $fairadd=trim(addslashes($_POST['fairadd'])); $faircity=trim(addslashes($_POST['faircity'])); $faircty=trim(addslashes($_POST['faircty'])); $fairstate=trim(addslashes($_POST['fairstate'])); $fairctry=trim(addslashes($_POST['fairctry'])); $fairopen=trim(addslashes($_POST['fairopen'])); $fairclose=trim(addslashes($_POST['fairclose'])); $fairmail=trim(addslashes($_POST['fairmail'])); $fairweb=trim(addslashes($_POST['fairweb'])); include("Connections/local.php"); $link = mysql_connect($hostname_local,$username_local, $password_local) or die("Could not connect"); mysql_select_db('fair123') or die("Could not select database"); $insert=mysql_query("INSERT INTO events (fairidnum, fairname, fairadd, faircity, faircty, fairstate, fairctry, fairopen, fairclose, fairmail, fairweb) VALUES('NULL', '$fairname', '$fairadd', '$faircity', '$faircty','$fairstate', '$fairctry','$fairopen', '$fairclose', '$fairmail', '$fairweb')")or die('couldn\'t Insert record into database :'.mysql_error()); header( 'Location: event_added.php' ) ; } ?> Especially look at the code part here $insert=mysql_query("INSERT INTO events (fairidnum, fairname, fairadd, faircity, faircty, fairstate, fairctry, fairopen, fairclose, fairmail, fairweb) VALUES('NULL', '$fairname', '$fairadd', '$faircity', '$faircty','$fairstate', '$fairctry','$fairopen', '$fairclose', '$fairmail', '$fairweb')")or die('couldn\'t Insert record into database :'.mysql_error()); header( 'Location: event_added.php' ) ; } ?> this is where I am having problems it was reading echo your record has been successfully added to the database What I want is for it to open up a new page with my menu and my css and all that good crap to a page where it will read the following Your information has been added to our database We have added Event name = "whatever the event's name was" Event address = "address:" so on and so on for all the fields in my form that was submitted to the database. with just using the echo command it always opened to just a blank page no formatting and no css as well as no all important links Can you please tell me what I'm doing wrong or where I can find a good guideline that Is easy to understand on how to do this? Thanks in advance Oh also I don't care if that page get's indexed by google or yahoo or not actually prefer it don't get indexed to be honest Hey guys i found this script that works great for what i need .. se i have this script that i did for my body (loan application) now i would like to export the info in a word doc <?php $ExcelFileName="test.doc"; header("Content-type: application/x-ms-download"); header("Content-Disposition: attachment; filename=$ExcelFileName"); header('Cache-Control: public'); $content=<<<EOD echo 'php'; whatever you want to write here including a php script it will be included in a string and then go in the output for a doc file EOD; echo $content; ?> so im trying to eco all the content in the database.. i tryed all the DB connection is there.. ao i place this after the (echo 'php' while($info = mysql_fetch_array($fileLIST)){; echo $info['PERS_F_NAME']; }; i get this? Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/autosspe/public_html/admin/loan/word.php on line 21 Hi guys, I'm trying to export records from php to ms word which appends text + image. i have got this code from http://www.thaicreate.com/php/php-word.application-addpicture.html Code: [Select] <html> <head> <title>ThaiCreate.Com PHP Word.Application Tutorial</title> </head> <body> <? $wdColorDarkRed = "&H80"; $wdAlignParagraphCenter = "1"; $wdAlignParagraphLeft = "0"; $wdParagraph = "4"; $wdHorizontalPositionMargin = "0"; $wdTableLeft = "-999998"; $wdCollapseEnd = "0"; $Wrd = new COM("Word.Application"); $DocName = "MyDoc/MyWord.doc"; //$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp $Wrd->Application->Visible = False; $WrdDoc = $Wrd->Documents->Add(); $MyRange1 = $WrdDoc->Paragraphs->Add->Range; $MyRange1->ParagraphFormat->Alignment = $wdAlignParagraphCenter; $MyRange1->Font->Name = "Verdana"; $MyRange1->Font->Size = "30"; $MyRange1->Font->Bold = True; $MyRange1->InsertBefore(chr(13).chr(13)."www.ThaiCreate.Com".chr(13)."Version 2009"); $MyRange1->InlineShapes->AddPicture(realpath("thaicreate-2009.gif")); //$WrdDoc->InlineShapes->AddPicture(realpath("thaicreate-2009.gif")); //$WrdDoc->Shapes->AddPicture(realpath("thaicreate-2009.gif"),0,0,MyRange1); //$WrdDoc->Shapes->AddPicture(realpath("thaicreate-2009.gif"),0,0,Wrd->Selection->Range); $MyRange2 = $WrdDoc->Paragraphs->Add->Range; $MyRange2->ParagraphFormat->Alignment = $wdAlignParagraphCenter; $MyRange2->Font->Name = "Verdana"; $MyRange2->Font->Size = "15"; $MyRange2->Font->Bold = True; $MyRange2->InsertBefore(chr(13).chr(13)."PHP,ASP and ASP.NET Tutorial"); $MyRange2->InlineShapes->AddPicture(realpath("doc.gif")); $MyRange3 = $WrdDoc->Paragraphs->Add->Range; $MyRange3->ParagraphFormat->Alignment = $wdAlignParagraphCenter; $MyRange3->Font->Name = "Verdana"; $MyRange3->Font->Size = "10"; $MyRange3->Font->Bold = True; $MyRange3->Font->Color = $wdColorDarkRed; $MyRange3->Underline = True; $MyRange3->InsertBefore(chr(13).chr(13).chr(13).chr(13)."All Rights Reserved"); //$WrdDoc->SaveAs($strPath."/".$DocName); $WrdDoc->SaveAs(realpath($DocName)); $Wrd->Application->Quit; $Wrd = null; ?> Word Created <a href="<?=$DocName?>">Click here</a> to Download. </body> </html> This is the best code i've found so far that guides on how to format the text in ms word via PHP. All set to go but one thing that I am trying to accomplish : to have a clickable email address (hyperlink) in the same ms word file. i have got this code somewhere from the net: Code: [Select] $MyRange3->Hyperlinks->Add({range}, 'http://www.google.com', '','',' hyperlink text to display'); // where {range} refers to as anchor according to that website this methods could be found in ms word visual basic editor (Alt+F11) then object browser (F2) when i replace the {range} above with let say variable $MyRange3. Code: [Select] $MyRange3->Hyperlinks->Add($MyRange3, 'http://www.google.com', '','',' hyperlink text to display'); The output will be produced but overwriting everything in $MyRange3 and displays only the hyperlink. I would like the email address (hyperlink) to appear at the end of $MyRange3 text. example output Code: [Select] All right reserved [u]hyperlink text to display[/u] anyone can shed some light on this. I have a CMS with basic toolbar and have major issues with copying and pasting from MS Word. I have a code below that I would like to test cleaning up MS Word.... Code: [Select] <?php function word_cleanup ($str) { $pattern = "/<(\w+)>(\s| )*<\/\1>/"; $str = preg_replace($pattern, '', $str); return mb_convert_encoding($str, 'HTML-ENTITIES', 'UTF-8'); } ?>And would like to add it onClick within code below, but it doesn't seem to do anything...... Code: [Select] <?php //we will have to dynamically generate either the edit and delete buttons or //the save button here depending on numevent. if($numMain!=-1) { echo("<tr><td colspan='2' align='center'><input type='submit' id='button' name='edit' value='Save Changes' onClick=\"saveChanges('edit'); onClick=\"function('word_cleanup');\"><input type='submit' id='button' name='delete' value='Delete' onClick=\"saveChanges('delete');\"></td></tr></table></form>"); } else { echo("<tr><td colspan='2' align='center'><input type='submit' id='button' name='save' value=' Save ' onClick=\"saveChanges('save'); onClick=\"function('word_cleanup');\"></td></tr></table></form>"); } ?> Any help, tips, suggestions would be so greatly appreciated. Hello Guys, I need some help here.. I want to implement a Bad word filter and not quite sure how to do it.. I am grabbing the following vars from the text fields $ad_title = filter_var($_POST['ad_title'], FILTER_SANITIZE_STRING,FILTER_FLAG_NO_ENCODE_QUOTES); $ad_body = filter_var($_POST['description'], FILTER_SANITIZE_STRING,FILTER_FLAG_NO_ENCODE_QUOTES); Then its inserted into the db. I would like to run it through this function first.. Code: [Select] FUNCTION BadWordFilter(&$text, $replace){ // fill this array with the bad words you want to filter and their replacements $bads = ARRAY ( ARRAY("butt","b***"), ARRAY("poop","p***"), ARRAY("crap","c***") ); IF($replace==1) { //we are replacing $remember = $text; FOR($i=0;$i<sizeof($bads);$i++) { //go through each bad word $text = EREGI_REPLACE($bads[$i][0],$bads[$i][1],$text); //replace it } IF($remember!=$text) RETURN 1; //if there are any changes, return 1 } ELSE { //we are just checking FOR($i=0;$i<sizeof($bads);$i++) { //go through each bad word IF(EREGI($bads[$i][0],$text)) RETURN 1; //if we find any, return 1 } } } // this will replace all bad words with their replacements. $any is 1 if it found any $any = BadWordFilter($wordsToFilter,1); I really would also like to query a table for any words that match and then use a replacement like [censored] Any help would be greatly appreciated! Hi: I can't seem to figure out how I would display the words the user enters in an ordered list on the bottom of the page in the <div id="guesses"> area. A hidden form variable is used to store all the previous guesses. (no cookies, no session variables). Also, how do I get the guesses to appear in the top of the page so that it looks like this: Array ( [myguess] => eee [alltheguesses] => aaa|ccc|ddd|ggg ) This is what I seem to be getting: Array ( [myguess] => yy [allTheGuesses] => ) Code: [Select] <?= '<pre>' . print_r($_POST,true) . '</pre>'; ?> <? $WORDS = array("grape","apple","orange","banana","plum","grapefruit"); define ("GUESSINDEX",3); define("THEWORD",$WORDS[GUESSINDEX]); foreach ($WORDS as $val){ if ('banana' == $val) echo 'found it.'; else echo 'not found.'; } if (in_array('plum',$WORDS == true)){ } foreach ($guessesarr as $val) echo "<li> $val</li>"; foreach ($WORDS as $val) echo "$val | "; echo "<br>"; echo implode(' | ',$WORDS); ?> <html> <style type="text/css"> body {background-color:orange} div {margin:10px} div#container {background-color: white; border: 3px solid black;width: 400px;margin-right: auto;margin-left: auto; text-align:center;} div#error {color:red} div#guesses,div#header p span {color:green; } h1,h2,h3 {color:#633} </style> <body> <div id="container"> <div id="header"> <p>grape | apple | orange | <span>banana</span> | plum | grapefruit</p> <h1>Word Guess</h1> <a href="<?$_SERVER['PHP_SELF']?>">refresh this page</a> </div> <div id="form"> <h3>Guess the word I'm thinking</h3> <form name="form1" method="post" action="<?=$_SERVER['PHP_SELF']?>" > <input name="myguess" type="text" value="<? echo $_POST['myguess']; ?>"> <input type="hidden" name="allTheGuesses" value = "<? echo $_POST['allTheGuesses']; ?>"> <input type="submit" value="GUESS"> </form> </div> <div id="error"> <? if ($_SERVER['REQUEST_METHOD'] == 'GET') echo "It's time to play the guessing game! (1)"; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $MYGUESS = trim($_POST['myguess']); if ($MYGUESS == "") echo "C'mon, guess something (2)"; elseif (in_array($MYGUESS,$WORDS) == false) echo "Hey, thats not even a valid guess. Try again (5)"; elseif ($MYGUESS == THEWORD) echo "You guessed " . THEWORD . " and that's CORRECT!!! (3)"; elseif ($MYGUESS <> THEWORD) echo "Sorry $MYGUESS is wrong. Try again (4)"; } ?> </div> <div id="guesses"> <center> <? echo "<ol>"; $allguesses = trim($_POST['allTheGuesses'],", "); $guessarr = explode(", ", $allguesses); foreach( $guessarr as $guess ){ echo "<li>$guess</li>"; } echo "</ol>"; ?> </center> </div> </div> </body> </html> Good evening, I hope some of you can bring me some hope to solve this problem. My client wants to create pdf files and let the user download it. He want's to design one word file and then import it to the application. After that the portal users can request it, which means that the application should take the word file, search and replace some keywords and then create the pdf file for download purposes. I see fpdf but this class only create pdf's. We can not convert from word or even search and replace in one pdf file. There is any solution that i can use bear in mind that our application is located in external servers? Looking forward for your help. Regards, HS Hey, I have a word filter which is dectecting strings that are only embedded in words. Which i don't want it to do. For example: If i want to filter "FR" and some one puts france - it flags it because france contains FR. How do i make it only look for "FR" on its own seperated from a word instead of it flagging nearly all words with the two letters together? Heres my filter: $text = 'testing'; //this should not return 1 // fill this array with the bad words you want to filter and their replacements $bads = array ("test"); foreach($bads as $key => $search_needle) { if(stristr($text, $search_needle) == TRUE) { return(1); break; } } I have a table in my php Mysql which contains some values.. Is it possible to get those values then export them to MS word with formatting? and make it like a table? Help pls. |