PHP - Loading A .docx With Phpword
Hi All,
Don’t know if any of you have any experience with PHPWord (actually a pretty cool library I stumbled upon), but worth a shot!
So either I’m missing something very obvious, or else I just have terrible luck. I am attempting to load a .docx file with PHPWord, set a value in it, and save the file. The issue is the saved file comes out as a blank word document, 7kb in size. The document I put in is large and has multiple pages. Obviously its not loading it right. My code is as follows:
$PHPWord = new \PhpOffice\PhpWord\PhpWord(); $document = $PHPWord->loadTemplate('Resources/documents/test.docx'); $document->setValue('theDate', '2014-07-25'); $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($PHPWord, 'Word2007'); $xmlWriter->save("php://output");I have tried with multiple test.docx files of different sorts, but the output file is always blank. Similar TutorialsI was just wondering if anyone new of a script of a function or a general direction to point me in of how to display a word document file on a website so that the users dont have to download it to see it. I know google does it so its not impossible I have (and will continue to) googled it and am clueless suggestions appricated. Mike Heintzman I know this won't be possible with DOC, but it should be with DOCX. Basically I want to have someone write up a docx file using special tokens in certain places. Then my PHP would find and replace those tokens when the users needs to. It would create and serve a NEW docx file with the tokens replaced. Any ideas on this? I'm reading up on a ton of libraries, but nearly all of them, their examples don't work out of the box. Thanks! I seem to have a problem with a PHP page I made. When executed on the server, it loads with a filesize 0 and for some browsers, says it does not exist. I believe that the cause is because it is not parsing due to a syntax error. I've busted my @$$ over this code, trying to find the issue, but cannot find it. Here is the whole page's code on pastie: http://pastie.org/1064160 Hello everyone, I have a PHP shopping cart I am working on. I have all my pictures stored in a folder url directory of my project. In my SQL database I have an image table that holds all of the image names. When I load the picture names with my php It somehow adds some extra random characters to the directory path: /img/%7B$row_product_image[name]%7D 404 (Not Found) If I hardcode the image directory img/picturename.jpg It works. Here is what I have. <?php include_once "objects/database.php"; include_once "objects/product.php"; include_once "objects/product_images.php"; // object instances $database = new Database(); $db = $database->getConnection(); $product = new Product($db); $product_image = new ProductImage($db); $recordsPerPage = 1; while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { extract($row); echo '<div class="col-md-4 mb-2">'; echo '<div class="product-id d-none">{$id}</div>'; echo '<a href="product.php?id={$id}" class="product-link">'; $product_image->product_id = $pid; $stmt_product_image = $product_image->readFirst(); while($row_product_image = $stmt_product_image->fetch(PDO::FETCH_ASSOC)) { echo '<div class="mb-1">'; echo '<img src="img/{$row_product_image[name]}" class="w-100" />'; echo '</div>'; } echo '<div class="product-name mb-1">{$name}</div>'; echo '</a>'; echo '</div>'; } class ProductImage { private $pdoConn; private $table_name = "product_images"; public $id; public $product_id; public $name; public $timestamp; public function __construct($dbconn) { $this->pdoConn = $dbconn; } function readFirst() { // SELECT query $query = "SELECT id, pid, name " . "FROM " . $this->table_name . " " . "WHERE pid = ? " . "ORDER BY name DESC " . "LIMIT 0, 1"; // prepare query statement $stmt = $this->pdoConn->prepare($query); // sanitize $this->product_id=htmlspecialchars(strip_tags($this->product_id)); // bind variable as parameter $stmt->bindParam(1, $this->product_id); // execute query $stmt->execute(); // return values return $stmt; } } ?>
Hi I have website where users can upload pictures on server. Sometimes it take 4-5 seconds until the upload it's finish. What can I do that when I click on upload button an icon appear in middle of the screen and disappear then the pictures was finish uploading. Thanks I got problem with one of my php page. Mozilla browser keeps on loading although it shows the page, i am not really sure which part is wrong. But i don't find any problem with other browsers lol. Can anyone help me please thanks in advance (I looked at the appropriate forums to put this in, but it seems I couldn't find a forum section specifically for this problem) Yesterday PHP on WAMP was working perfectly. So I shutdown the computer, go to sleep, and wake up and turn WAMP on. But for some odd reason, when none of my PHP files are loading properly. It just shows all the code as if it were a .txt file. Any reasons for this? Hi! This code, which is basically HTML and Javascript, echoed in PHP (as you can see in the attached image), has functioned well for a long time. It still does, if put in a page by itself. The problem now is when it is integrated in other PHP scripts. It does not work this way on either the live server or on WAMP anymore. This script is normally setup to be execute about half way through the complete script of the page and has functioned well, showing approx. the top half of the page, as well as a loading gif. When the PHP workload is complete, the loading gif is removed and the rest of the page is displayed. Now with the later versions of PHP, all I see is a blank page until all the script is executed, which can take about 15 seconds or more. PHP does not release the information to Apache, or if it does, Apache does not do anything with it. I have tried different approaches, using ob_flush() and so on, but it just will not function. I would like to know if someone else has had this issue, or knows about it and if there is any current solution. I have not managed to find any working solution that will work with PHP 7.4 and in the future, on the net. I know one cannot predict all the changes that will occur with PHP in the future, but I would like the solution to function for at least 3-5 future versions. I am now going to try something completely different outside the box and create a start page instead. If it does work, it will just be a temporary solution though. Thanks for any assistance beforehand. Mac Edited October 24, 2020 by MacDknife spelling error Hey guys, Problem: php script keeps loading and i dont know why. What I've done so far is commenting out line-by-line so I found out that the problem is somewhere he Code: [Select] <div id="wrapper"> <div id="inner"> <div id="top"> <?php require 'basic/logo.php';?> <?php require 'basic/header.php';?> </div> its not working - keeps loading. Commenting out the 'required' stuff it works... error_reporting(E_ALL); is on... what the hell is the problem?! the files are there in /basic. Just dont know any further! i'm new to php and don't really know where to start here... i'm automating a system that scrapes a site for a particular pdf download link (got this far), downloads it, parses the pdf, etc... problem is that you must be logged in (while viewing in the browser) in order to access the pdf... if you're not logged in, you are redirected and the download fails... i do have a proper login... how would i go about utilizing my login in order automate the pdf download? is there a way to send the login with the url request? or open a stream, login, and retry the download? thanks Lets say that I have an array that I want to convert to a value object My value object class is as follows: /* file UserVO.php*/ class UserVO { public $id; public $email; public function __construct($data) { $this->id = (int)$data['id']; $this->email = $data['email']; } } And I create my array of value objects as follows: /* file UserService.php*/ $array = array( array(...), array(...)); $count = count($array); for ($i = 0; $i < $count; $i++) { $result[] = new UserVO($array[$i]); } return $result; OK, so this all works fine. However, I'd like to specificy the VO that is to be created dynamically, so that I can have a single dynamic function to create my VO's. Something like: $ret = create_vo($array, 'UserVO'); function create_vo($data, $vo) { $count = count($data); for ($i = 0; $i < $count; $i++) { $result[] = new $vo($array[$i]); //this obviously wont work...Class name must be a valid object or a string } return $result; } I realise that I could do this with a switch statement (iterating through all my VO's)...but there is no doubt a much much more elegant solution. It would also be supercool if I could lazy load the VO's as needed, instead of having multiple 'includes' Any help much appreciated. Okay the reason I'm doing it this way is because I work locally and then transfer them to the production site. For some reason, this isn't working even though when I view the page source, it has the right URL, but when it's clicked it goes to a blank page, but when I copy and paste, it goes to the right page. Anywho, this is what I'm trying: Code: [Select] <?php $homeURL = 'localhost:90/Elvonica'; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Elvonica</title> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <link rel="stylesheet" type="text/css" href="<?php echo $homeURL; ?>/template/css/skySpirit.css" /> I didn't plug in the rest to ignore it since it's not part of the problem. It's printing: localhost:90/Elvonica/template/css/skySpirit.css, but when it's clicked, goes to blank page. When it is copied and pasted, it goes to the right page. I have a feeling you can't include PHP inside a link rel or any sort of that header information. If anyone could please help me how to do this, I would appreciate it. FYI: I did have just template/css/skySpirit.css and it worked until I go into a another directory like forums/index.php. Then it tries to go localhost:90/Elvonica/forums/template/css/skySpirit.css and it's not in there obviously. Thank you for anything that you can offer! I know how to do the includes with the dirname(__FILE__). I am running php on one computer at work and want other users on other computers to access the index page by sharing it.after mapping the page, I see no data on the other machine. Does php, as pache need to beer installed on other computers footer it too work properly I've installed Drupal 7.1 on my computer and I'm trying to access it via localhost. However, the site does not load the "index.php" file. Instead, I get the list of files and folders in the working directory with the heading "Index of /drupal71" (drupal71 is the temporary site name). The .htaccess file has the following lines, so I'm confused as to why index.php doesn't load automatically. Code: [Select] # Set the default handler. DirectoryIndex index.php index.html index.htm Any suggestions? Hi, I have uploaded a website for someone but they are having problems viewing it and are telling me that nothing comes up. Not sure if its a dns problem. The domain was registered 2 days ago. Can a couple of you please check and tell me if this site loads up, it should show an ecommerce website : http://www.cassellmotors.com Many thanks, Scott I have some issue with the website just created specifically http://ecolandscaping.co/index.php?m=3 and hosted on the 000webhosting.com. It loads the page slowly. Things what i have consideredto trie to improve better performance: * optimized CSS files * optimized MySQL queries with specifying the rows wanted (SELECT ID, IMAGE.....) * avoid to select an image saved as blob if not necessary etc. * made different image retrieving php files P.S. the website is small of size approx 700KB for loading. Problem is that not all the images (saved in MYSQL BLOB) are loaded successfully. Could anyone have a look and advice what else could cause the performance issue. P.S.S. I do take in account that this isthe free hosting and may cause some problems Hi, not sure if this is the correct forum, so apologies, i assumed it was a php problem. Anyway, all of the pages on my site are permanently loading. http://dev.subverb.net contains a few external scripts from twitter and facebook, so I assumed it could be that, but even ones like http://dev.subverb.net/mix.php always are loading. I can't figure out on firebug how to find what is loading, because it doesnt seem to tell me in the net profile, just what has already been loaded. Any help? i'm having issue related getting URL content properly FB:LIKE first link work properly but other links wouldn't work properly mypage.php code is simple mysql connectivity Code: [Select] $httplink = "localhost/mypage.php?mypage=" ; while($row = mysql_fetch_assoc($rs)) { echo "<tr>"; echo "<td> {$row['id']}</td>"; echo "<td><fb:like href=\"{$httplink}{$row['id']}\" layout=\"button_count\" show_faces=\"false\" width=\"100\" font=\"tahoma\" colorscheme=\"dark\"></fb:like></td>"; echo "<td> {$row['title']} </td>" ; echo "<td> <a href =\"{$row['http']}{$row['link']}\" target = \"_blank\" >{$row['http']}{$row['link'] }</a> </td>" ; echo "</tr>"; } mypage.php : <?php $link = mysql_connect('localhost', 'root', '1234'); if (!$link) die('Could not connect: ' . mysql_error()); $status = mysql_select_db('fblike', $link ); if(!$status) die("Failed to select database!"); if (!empty($_GET['mypage'])) { $result = mysql_query("SELECT * FROM mytable WHERE id={$_GET[mypage']} "); if (!$result) die('Invalid query: ' . mysql_error()); $rows = mysql_fetch_row($result); echo "<html>"; echo "<head>"; echo "<title>{$rows[1]} </title>"; echo "</head>"; echo "<body>"; echo "{$rows[1]} "; echo "</body>"; echo "</html>"; } mysql_close($link); ?> My website www.staceyxsolomon.com is only loading the header of my index.PHP page The full page is there i had double checke in the FTP It happened after my host put me onto another server, all settings carried over, please can somebody advise help if this is PHP related? Hi All I have a site which is built from 3 folders: folder1 frolder2 frolder3 folder1 is the "master" folder. Means, In it I have the login page, connecxtion to DB elements, and header, footer and bootstrap treeview sidebar which I want to use in all the pages of the site. folders 2 and 3 each store all pages concern a specific vertical. The sidebar, which is located at folde1 retrive the content from database using AJAX, and Ive overloaded some of the original css by using custom css. here is psrt of the sidebar code: <link href="custom.css" type="text/css" rel="stylesheet" madia="all"/> <script type="text/javascript"> $(document).ready(function() { var treeData; $.ajax ({ type: "GET", url: "fill_sidebar.php", dataType: "json",
When I load this sidebar to pages inside folder1 all works great The loading is done by this code: <script> $(document).ready(function () { $('#sidebar').load('sidebar.php'); }); </script> The loading for folder 2 is done by this code: <script> $(document).ready(function () { $('#sidebar').load('../folder2/sidebar.php'); }); </script>>
When I try to load it to pages from other folder2 or 3 I get erroe message (in developer tools):
folder2/custom.css net::ERR_ABORTED 404 (Not Found) Of course, I i copy these files to folder2 all works fine, but I dont want to do that. I want to maintain only one file. My question is how to make these loads relative to the page I load? |