PHP - What Is The Best Way To Handle Pdf To Jpg Page Number Conversions
I have a script that takes a 2 or 3 page pdf, uploads it and hashes the file name to something that isn't guessable.
We now want to add an image of each of the PDF for users who don't have Adobe Reader. Some pdf's will be 2 and some 3 pages. Should I: A) Let convert name the different pages "*-0.jpg, *-1.jpg..." and then use a recursion function (it's already written for another reason) to crawl the folder, B) Use a PHP/PDF library to determine the number of pages, then add the value to the database's corresponding row. C) Use a hybrid of both D) Any better ideas??? Thanks Similar TutorialsHi All. New at this, form is working perfect, then added recapthca, now it only handles recaptcha and not the form. not sure where the error is
Please help me out with sessions . I m new to this topic.
This is my code for displaying images from a folder:
function generate_img ($imagepointer, $imageornot){ if($imageornot == 1){ $var = getcwd(); $dirlocation = $var."\\imageuploads\\".$imagepointer; $files = array_diff(scandir($dirlocation), array('..', '.')); foreach ($files as $image){ $data[] = array('label' => '<img src="/imageuploads/'.$imagepointer.'/'.$image.'" alt="thumbnail"> <br/>'); }; return $data; } else { return FALSE; } } I'm using it with print_r: <p><?php print_r(generate_img($imagepointer, $imageornot)); ?></p> Working ok, but obviously not good for a live site. Is implode() a good idea in this situation? And how would I use it? Appreciated. Let's say there is an application where a user would like to use English and Metric systems to enter values. For example, to handle customer orders where customers give data in this or that system, (but not both).
From the user-view, all the user cares about is if they can select English or Metric system, enter their values, click submit, and have their data added to the page in their choice of system, and have their values (and choice of system) stay the same.
The back end however is set up to do "compute" operations with English system in mind only. So inside back end, before the compute module, all the values should be converted to English. Some things like precomputed constants, that exist in computations are in English unit of measurements.
So I have attached an image of what I am thinking ..
* first (top) way is one where the front-end takes care of conversions. Back-end is not aware of another system (which makes it difficult sometimes, when trying to display a page back to the user saying "We know you chose system X"), and being aware of chosen system is something that I think is beneficial.
* the second (bottom) way is where front end is merely a passing device to back end, and bac-end takes care of conversions. Back-end is also aware of the two systems
My question is -- is there a preferred way to design an application when it comes to considerations above? Have a system-aware back-end, or try to localize system to front end only?
Attached Files
ways of encoding unit system.png 207.92KB
0 downloads I'm getting the dreaded " Invalid parameter number: number of bound variables does not match number of tokens" error and I've looked at this for days. Here is what my table looks like:
| id | int(4) | NO | PRI | NULL | auto_increment | | user_id | int(4) | NO | | NULL | | | recipient | varchar(30) | NO | | NULL | | | subject | varchar(25) | YES | | NULL | | | cc_email | varchar(30) | YES | | NULL | | | reply | varchar(20) | YES | | NULL | | | location | varchar(50) | YES | | NULL | | | stationery | varchar(40) | YES | | NULL | | | ink_color | varchar(12) | YES | | NULL | | | fontchosen | varchar(30) | YES | | NULL | | | message | varchar(500) | NO | | NULL | | | attachment | varchar(40) | YES | | NULL | | | messageDate | datetime | YES | | NULL |Here are my params: $params = array( ':user_id' => $userid, ':recipient' => $this->message_vars['recipient'], ':subject' => $this->message_vars['subject'], ':cc_email' => $this->message_vars['cc_email'], ':reply' => $this->message_vars['reply'], ':location' => $this->message_vars['location'], ':stationery' => $this->message_vars['stationery'], ':ink_color' => $this->message_vars['ink_color'], ':fontchosen' => $this->message_vars['fontchosen'], ':message' => $messageInput, ':attachment' => $this->message_vars['attachment'], ':messageDate' => $date );Here is my sql: $sql = "INSERT INTO messages (user_id,recipient, subject, cc_email, reply, location,stationery, ink_color, fontchosen, message,attachment) VALUES( $userid, :recipient, :subject, :cc_email, :reply, :location, :stationery, :ink_color, :fontchosen, $messageInput, :attachment, $date);"; And lastly, here is how I am calling it: $dbh = parent::$dbh; $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); if (empty($dbh)) return false; $stmt = $dbh->prepare($sql); $stmt->execute($params) or die(print_r($stmt->errorInfo(), true)); if (!$stmt) { print_r($dbh->errorInfo()); }I know my userid is valid and and the date is set above (I've echo'd these out to make sure). Since the id is auto_increment, I do not put that in my sql (though I've tried that too), nor in my params (tried that too). What am I missing? I feel certain it is something small, but I have spent days checking commas, semi-colons and spelling. Can anyone see what I'm doing wrong? <?php $con=mysqli_connect("address","username","pass","db name"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } if (!(isset($pagenum))) { $pagenum = 1; } $data = mysqli_query($con,"SELECT * FROM info"); $rows = mysql_num_rows($data); $page_rows = 15; $last = ceil($rows/$page_rows); if($pagenum < 1); { $pagenum = 1; } elseif ($pagenum > $last); { $pagenum = $last; } $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; $result = mysql_query($con,"SELECT * FROM topsites $max") or die(mysql_error()); echo "<table border='1' class='boldtable' cellpadding='2'> <tr> <th>Creditor</th> <th>dd/mm/yyyy</th> <th>Credit Score</th> <th>State</th> <th>Income</th> <th>Approval</th> <th>Credit Line</th> <th>Interest</th> <th>Comment</th> </tr>"; while($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['creditor'] . "</td>"; echo "<td>" . $row['date'] . "</td>"; echo "<td>" . $row['fako'] . "</td>"; echo "<td>" . $row['state'] . "</td>"; echo "<td>" . $row['income'] . "</td>"; echo "<td>" . $row['approval'] . "</td>"; echo "<td>" . $row['creditline'] . "</td>"; echo "<td>" . $row['interest'] . "</td>"; echo "<td>" . $row['comments'] . "</td>"; echo "</tr>"; } echo "</table>"; echo " --Page $pagenum of $last-- <p>"; if ($pagenum == 1) { } else { echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> "; } echo " ---- "; if ($pagenum == $last) { } else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> "; } mysqli_close($con); ?>All I want are the pages broken up into pages. It is going wrong somewhere before my table. Can someone help me out? Thank you! I need to come up with a script that will get the number of products under a category and return the number of products shown on each page in Showing 1-20 Products out of (total number) I have this MYSQL which I'm also using to generate pagination. Code: [Select] $query5 = "SELECT COUNT(*) as num FROM $tbl_name WHERE product_category='$cat'"; $total_pages = mysql_fetch_array(mysql_query($query5)); $total_pages = $total_pages[num]; /* Setup vars for query. */ $targetpage = "store.php?cat=".$cat; //your file name (the name of this file) $limit = 20; //how many items to show per page $page = $_GET['page']; if($page){ $start = ($page - 1) * $limit; //first item to display on this page } else{ $start = 0; //if no page var is given, set start to 0 } The products are pulled from the database he Code: [Select] $sql30 = "SELECT * FROM $tbl_name WHERE product_category='$cat' LIMIT $start, $limit"; $result30 = mysql_query($sql30); I came up with one way, but it will only work when there are 20 products on the page. If there's less it won't calculate that amount. my coding is displaying all result in only one page.i want to limit it to 50result per page..can anyone give the suitable coding? right now,im using this <?php do { ?> <?php if ($totalRows_Recordset1 > 0) { // Show if recordset not empty ?> <tr bgcolor="#CCCCCC"> <td height="21"><div align="center"><span class="style17"> <?php $count=$count + 1; echo $count; ?> </span></div></td> <td><div align="center" class="style17"><?php echo $row_Recordset1['id']; ?></div></td> <td><div align="left" class="style17"><?php echo $row_Recordset1['name']; ?></div></td> <td><div align="center" class="style17"><a href="staf_info.php?id=<?php echo $row_Recordset1['id']; ?>"><img src="pic/b_view.png" width="16" height="16" border="0" /></a></div></td> <td><div align="center" class="style17"><a href="kemaskini_staf.php?id=<?php echo $row_Recordset1['id']; ?>"><img src="pic/b_edit.png" width="16" height="16" border="0" /></a></div> <div align="center" class="style17"></div></td> <td><div align="center" class="style17"><a href="staf_delete.php?id=<?php echo $row_Recordset1['id']; ?>"><img src="pic/b_drop.png" alt="padam" width="16" height="16" border="0" /></a><a href="staf_delete.php?id=<?php echo $row_Recordset1['id']; ?>"></a></div></td> </tr> <?php } // Show if recordset not empty ?> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> I have a bunch of pdf's and I want to extract text from the last page of every pdf. I have a function to count the number of pages in each pdf. Does anyone know of a way that I could extract file from a specified file and page number. example: getData('example.pdf', 54); Hi everyone, I have this script that identify's the current page in the navigation Code: [Select] <?php $currentPage = basename($_SERVER['SCRIPT_NAME']); ?> <ul id="nav"><!-- Open Nav --> <li><a href="index2.php" <?php if ($currentPage == 'index2.php') {echo 'class="selected"';} ?>>Home</a></li> <li><a href="salon-information.php" <?php if ($currentPage == 'salon-information.php') {echo 'class="selected"';} ?>>Salon Information</a></li> <li><a href="about-us.php" <?php if ($currentPage == 'about-us.php') {echo 'class="selected"';} ?>>About us</a></li> <li><a href="hair-care-advice.php" <?php if ($currentPage == 'hair-care-advice.php') {echo 'class="selected"';} ?>>Hair Care Advice</a></li> </ul><!-- Close Nav --> My problem is that hair-care-advice.php has a number of sub pages. How do I get it so the selected class remains selected for all the sub pages as well as the main page. Any help would be greatly appreciated Thank you Barry <!DOCTYPE html> <html> <head> <script> $(document).ready(function() { if($("#getPIN").click(function(){ <?php $char = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW XYZ1234567890'; $generated_password = substr(str_shuffle($char), 0, 10); ?> var genNumber; $("#txtpin").val() = genNumber; return false; })); }); </script> </head> <body> <input type = "text" name = "txtpin" id = "txtpin" value = ""> <input type = "button" name = "getPIN" id = "getPIN" value = "getPIN"> </body> </html> Hey you guys need your help... Basically what im trying to do is when the user clicks the getPIN button, the value generated using php is assigned to the txtpin textfield without refreshing the page.... thanks alot guys.... This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=326408.0 Hello,
I have problem durring binding update query. I can't find what is causing problem.
public function Update(Entry $e) { try { $query = "update entry set string = $e->string,delimiter=$e->delimiter where entryid= $e->id"; $stmt = $this->db->mysqli->prepare($query); $stmt->bind_param('ssi',$e->string,$e->delimiter,$e->id); $stmt->close(); } catch(Exception $ex) { print 'Error: ' .$ex->getMessage(); } }When I run function update I'm getting next error:Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement Can you help me to solve this problem ? Edited by danchi, 17 October 2014 - 10:25 AM. I need to display a number(the number is retrieved from the db) in the form input field such that only the last 4 digits is visbile, the remaining can be masked as * or X or whatever is applicable. I know the last 4 can be obtained as follows: Code: [Select] $number=substr($number,-4,4); But when i hit the submit button the form validates the input field and checks if the number is a valid number of a specific format. Therefore when I click on the submit button then I should still be able to unmask the masked numbers or do something similar that would help me validate the whole number. Code: [Select] <input type="text" name="no" value="<?php if(!empty($number)){ echo $number;} ?>"> So i got a table that looks somthing like this: File Name | Download | Suggested Catagory | Select Catagory | Approve -------------------------------------------------------------------------------------- test | Download | blah blah blah | Option menu | yes or no option menu test | Download | blah blah blah | Option menu | yes or no option menu test | Download | blah blah blah | Option menu | yes or no option menu what I want to do is in the file that processes this it only looks at the ones that have had the "approve column" submitted as a yes. Next it will to a mysql entry into verrified notes. Problem is with X amount of entries in that form I dont know how to look at only the ones that have said yes. Do I create a new form for each entry or put them all as one entry and after this what do I do next? So I'm sitting at my desk scratching my head on how to do a task where I pull information form a database (that i know how to do) but then i need to see if two variables equal a string and if they do count out how many times that two variables equal there two string checks and out put the counted number ? this is what I have thought of but dose not to work because I cant figure out a way to code it? $dbPull = mysql_fetch_array($result) if( $dbPull['Foo'] == 'string1' && $bdPull['Bar'] == 'string2') this is were I get lost I'm looking for (how many times in the DB dose String2 show up in the array were the above, IF statement is true ) any ideas would be most appreciated Okay, so now I need help evolving my Log-In system... Up until now, the only place a user could log-in was on a given Article page if they wanted to add a comment to the Article. To accommodate that feature, I was setting the "Return To Page" only in my "article.php" script like this... Code: [Select] $_SESSION['returnToPage'] = $_SERVER['SCRIPT_NAME'] . '?title=' . $articleTitle; However, now I want to expand things. I'm growing increasingly confused about how to manage where to route people when they long-in?! 1.) Sometimes a user will Log-In and want to return where they were at (e.g. index.php, article1234.php) 2.) Sometimes a user might want to continue down a path (e.g. Checking Out, Registering for a Workshop, Sending a Message) Is there some kind of strategy to handle this? (nothing over complex, but there must be some Best Practices that work?! Debbie I have 2 PHP scripts : opendb.php and closedb.php In opendb.php I have this code :
<?php
In closedb.php I have this code :
<?php When I run opendb.php I get the expexted message "DB Open." But when running the closedb.php , I get an error 500. I was hoping to be able to pass the Handle, needed to operate in my database, between PHP scripts, by pushing it into $_SESSION['dbhandler'] , and retreiving it in other scripts. Is this possible ? Regards,
Martin I have just completed a modest way for Users to post Comments on Articles my website. However, the thought occurred to me today, that I haven't given Users the ability to Preview or Edit their comments after submittal. What is the best way to store info on a Comments Form so you can re-display it for Preview/Editing?? (I'm not really sure how the workflow would work for this?!) Do I capture the Comments Form Data and store it in a Session? Or in my Database? Or do something else? Security is always a concern of mine too!! Thanks, Debbie May you help me with how to get a file handle for a checkbox. I mean something that will output a 1 or 0... thank you |