Jump to content

imperium2335

Members
  • Posts

    385
  • Joined

  • Last visited

Everything posted by imperium2335

  1. I am trying to create a rewrite rule that will let me keep the following URL clean: <script type="text/javascript" src="http://www.mysite.com/views/Page/js/jsfile1.js"></script> To be: <script type="text/javascript" src="http://www.mysite.com/js/jsfile1.js"></script> When I want to include JS and CSS files in any given view, I call: $this->view->js = array('Page/js/jsfile1.js', 'Page/js/jsfile2.js') ; Where Page would change according to the controller you are currently in. E.g. If I am on www.mysite.com/contact, any JS I load be redirected to: www.mysite.com/views/contact/js/jsfile1.js But in the header of my contact page you would only see: <script type="text/javascript" src="http://www.mysite.com/js/jsfile1.js"></script> How can this be done? Or does someone know of a better way to not expose the system directories such as /views etc in a PHP MVC framework (this is my own mini custom framework BTW)? I hope I'm making sense!
  2. Thanks for your reply. No, I only have one thing called invoiceTable, and that is the abstract one I'm creating in this query, no other tables exist with that name.
  3. Jesus cake, I figured it out. Here is the solution in case it helps anyone else: $imgSrc = $_POST['imagePath'.$_GET['img']] ; $thisX1 = $_POST['image' . $_GET['img'] . 'X1'] ; $thisY1 = $_POST['image' . $_GET['img'] . 'Y1'] ; $thisX2 = $_POST['image' . $_GET['img'] . 'X2'] ; $thisY2 = $_POST['image' . $_GET['img'] . 'Y2'] ; $original = imagecreatefromjpeg($imgSrc) ; list($widthOriginal, $heightOriginal) = getimagesize($imgSrc) ; list($width, $height, $ratio) = imageResize($widthOriginal, $heightOriginal, 204) ; $thumbCanvas = imagecreatetruecolor(150, 150) ; $srcX = round($thisX1/$ratio) ; $srcY = round($thisY1/$ratio) ; $sWidth = $thisX2 - $thisX1 ; $sHeight = $thisY2 - $thisY1 ; imagecopyresampled($thumbCanvas, $original, 0, 0, $srcX, $srcY, 150, 150, $sWidth/$ratio, $sHeight/$ratio) ; imagejpeg($thumbCanvas, '../uploads/thumbnail.jpg') ; echo '<img id="image' . $_GET['img'] . '" src="' . '../uploads/thumbnail.jpg' . '" />' ;
  4. Hi, I have an interface where the user picks an image to upload, it then uploads the original (big) image. That same image then appears but at a reduced size of 150px max height or width, the size is defined in the img tag using height="XX" width ="XX", so it is the same image file, just with its dimensions set in the html. The user then drags a div over the image to crop it. The problem I am having is getting the reference image crop dimensions to translate to the actual full size image. Have attached an image of what the result is. What formula do I need to get it to translate to the bigger image properly? Here is my code: if($_GET['mode'] == 'imageupload') { $imgNumber = $_GET['img'] ; $fileName = strtolower($_FILES["setFile$imgNumber"]['name']) ; $ext = explode('.', $fileName) ; if($ext[1] != 'jpg' && $ext[1] != 'JPG' && $ext[1] != 'jpeg') { echo "<span class='iFOutput'>Can only accept JPG images.<br /><br /> The image you tried to upload was '" . $ext[1] . "'.</span>" ; exit() ; } $tmpName = $_FILES["setFile$imgNumber"]['tmp_name'] ; move_uploaded_file($tmpName, '../uploads/' . $fileName) ; $sizeInfo = getimagesize('../uploads/' . $fileName) ; $resizedArray = imageResize($sizeInfo[0], $sizeInfo[1], 204) ; $finalImageSrc = '../uploads/' . $fileName ; echo '<img id="image' . $imgNumber . '" src="' . $finalImageSrc . '" width="' . $resizedArray[0] . '" height="' . $resizedArray[1] . '" />' ; // SCALED IMAGE FOR CROPPING INTERFACE } elseif($_GET['mode'] == 'imagecrop') { $imgSrc = $_POST['imagePath'.$_GET['img']] ; $thisX1 = $_POST['image' . $_GET['img'] . 'X1'] ; $thisY1 = $_POST['image' . $_GET['img'] . 'Y1'] ; $thisX2 = $_POST['image' . $_GET['img'] . 'X2'] ; $thisY2 = $_POST['image' . $_GET['img'] . 'Y2'] ; $original = imagecreatefromjpeg($imgSrc) ; list($width, $height) = getimagesize($imgSrc) ; if ($width > $height) { $ratio = (150 / $width); } else { $ratio = (150 / $height); } echo $ratio ; $thumbCanvas = imagecreatetruecolor(150, 150) ; $thisX1 = round($thisX1/$ratio) ; $thisY1 = round($thisY1/$ratio) ; imagecopyresampled($thumbCanvas, $original, 0, 0, $thisX1, $thisY1, 150, 150, $width, $height) ; imagejpeg($thumbCanvas, '../uploads/thumbnail.jpg') ; echo '<img id="image' . $_GET['img'] . '" src="' . '../uploads/thumbnail.jpg' . '" />' ; }
  5. Hi, Does anyone know why it won't recognise my abstract table? I get the error " PDO::query() [pdo.query]: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'overseer_ims.invoicetable' doesn't exist" SELECT (SELECT SUM(invoiceTable.total) FROM invoiceTable WHERE invoiceTable.jobRef = jobs.id) AS total FROM invoices_out, jobs, invoices_out_reference, enquiries, entity_details, (SELECT jobRef, SUM(invoices_out.net+invoices_out.vat) AS total FROM invoices_out, invoices_out_reference WHERE invoices_out_reference.invoiceRef = invoices_out.id GROUP BY jobRef) AS invoiceTable WHERE invoices_out_reference.jobRef = jobs.id AND invoices_out_reference.invoiceRef = invoices_out.id AND enquiries.id = jobs.enquiryRef AND invoiceTable.jobRef = jobs.id AND enquiries.entityRef = entity_details.id
  6. Sorry guys my bad, I just realised I didn't put any indexes on my reference table columns...
  7. Hi, I am having a problem with a part of my query: "SELECT SQL_CALC_FOUND_ROWS jobs.id AS jobId, enquiries.id AS profId, users.username, entity_details.name AS entityName, branches.name AS branch, orderNumber, entity_vat_numbers.vatCode, entity_account_numbers.accountNumber, (SELECT symbol FROM parts_trading, currencies WHERE parts_trading.enquiryRef = enquiries.id AND parts_trading.sellingCurrency = currencies.id LIMIT 1) AS symbol, (SELECT SUM(quantity) FROM parts_trading WHERE enquiryRef = enquiries.id) - COALESCE((SELECT SUM(quantity) FROM invoices_out_reference WHERE jobRef = jobs.id), 0) AS differentPartsCount, (SELECT SUM(quantity*sellingNet) FROM parts_trading WHERE parts_trading.enquiryRef = enquiries.id) - COALESCE( (SELECT SUM(invoices_out.net) FROM invoices_out, invoices_out_reference WHERE invoices_out_reference.invoiceRef = invoices_out.id AND invoices_out_reference.jobRef = jobs.id ) , 0) AS netRemaining, (SELECT SUM(quantity*sellingVat) FROM parts_trading WHERE parts_trading.enquiryRef = enquiries.id) - COALESCE( (SELECT SUM(invoices_out.vat) FROM invoices_out, invoices_out_reference WHERE invoices_out_reference.invoiceRef = invoices_out.id AND invoices_out_reference.jobRef = jobs.id ) , 0) AS vatRemaining, (SELECT SUM(quantity*(sellingNet+sellingVat)) FROM parts_trading WHERE parts_trading.enquiryRef = enquiries.id) - COALESCE( (SELECT SUM(invoices_out.net+invoices_out.vat) FROM invoices_out, invoices_out_reference WHERE invoices_out_reference.invoiceRef = invoices_out.id AND invoices_out_reference.jobRef = jobs.id ) , 0) AS totalRemaining FROM jobs, enquiries, users, branches, entity_details LEFT JOIN entity_account_numbers ON entity_details.id = entity_account_numbers.entityRef LEFT JOIN entity_vat_numbers ON entity_details.id = entity_vat_numbers.entityRef WHERE enquiries.traderRef = users.id AND jobs.enquiryRef = enquiries.id AND users.branchRef = branches.id AND (SELECT SUM(quantity) FROM parts_trading WHERE enquiryRef = enquiries.id) - COALESCE((SELECT SUM(quantity) FROM invoices_out_reference WHERE jobRef = jobs.id), 0) > 0 AND enquiries.entityRef = entity_details.id" I know for certain that it is the part: "AND (SELECT SUM(quantity) FROM parts_trading WHERE enquiryRef = enquiries.id) - COALESCE((SELECT SUM(quantity) FROM invoices_out_reference WHERE jobRef = jobs.id), 0) > 0" That is causing the problem. Unfortunately this is a vital part of my query used for not displaying rows that have quantities matching the sum of what is in the other table . Is there are more efficient way to get the same result than that part of the query?
  8. Thanks! That is exactly what I wanted. I guess this is how they fake an AJAX file upload.
  9. Hi, I am trying to create a file uploader by following an online tutorial about AJAX file uploading. Due to the nature of my system, I need to override the the form submit function. That is, instead of submit the form by pressing the typical form submit button, I want to submit the form using my function (which is a button in a jquery ui dialog box). How can I do this? ( I have attached a screenshot) Here is my form for the file upload part in the dialog: <form id="imageList" method="post" enctype="application/x-www-form-urlencoded" target="hiddenUpload"> <input name="firstFile" type="file" /> <iframe id="hiddenUpload" name="hiddenUpload" onload="" style="width:0px;height:0px;border:none;"></iframe> </form>
  10. A simple example of using prepared statements would be: $name = $_POST['userSubmitedData'] . '%' ; include('myDatabaseConnectionData.php') ; $result = $dbh->prepare("SELECT id FROM users WHERE name LIKE ?") ; $result->bindParam(1, $name , PDO::PARAM_STR ; $result->execute() ; while($row = $result->fetch(PDO::FETCH_ASSOC)) { // Do stuff. }
  11. Also, does anyone know why bindParam doesn't work? It's why I used bindValue instead.
  12. Hi, I got tired of typing out the same bindParam etc etc so I came up with the function below. As long as you enter your variables into the array in the same order as your placeholders, it works well. Please let me know your thoughts on how to make it better or perhaps there is a method out there that already exists which makes this function pointless!? function autoBind($SQL, $varsArray, $mode = 'FETCH_ASSOC') { include('dbconnect.php') ; $result = $dbh->prepare($SQL) ; $i = 1 ; foreach($varsArray as $current) { if(is_numeric($current)) { $result->bindValue($i, $current, PDO::PARAM_INT) ; } else // Must be string. { $result->bindValue($i, $current, PDO::PARAM_STR) ; } $i++ ; } $result->execute() ; if($mode == 'FETCH_ASSOC') { $output = $result->fetch(PDO::FETCH_ASSOC) ; } elseif($mode == 'FETCHCOLUMN') { $output = $result->fetchColumn() ; } return $output ; }
  13. Hi, I have a query that calculates three totals in three different currencies, so there are 3 rows output each with 3 columns. $result = $dbh->query("SELECT SUM(((SELECT SUM((quantity*(sellingNet+sellingVat))) FROM parts_trading WHERE parts_trading.enquiryRef = enquiries.id AND parts_trading.sellingCurrency = 1)+(SELECT SUM(feeAmountNet+feeAmountVat) FROM enquiries_custom_fees WHERE enquiries_custom_fees.enquiryRef = enquiries.id))) AS salesTotalPounds, SUM(((SELECT SUM((quantity*(sellingNet+sellingVat))) FROM parts_trading WHERE parts_trading.enquiryRef = enquiries.id AND parts_trading.sellingCurrency = 2)+(SELECT SUM(feeAmountNet+feeAmountVat) FROM enquiries_custom_fees WHERE enquiries_custom_fees.enquiryRef = enquiries.id))) AS salesTotalDollars, SUM(((SELECT SUM((quantity*(sellingNet+sellingVat))) FROM parts_trading WHERE parts_trading.enquiryRef = enquiries.id AND parts_trading.sellingCurrency = 3)+(SELECT SUM(feeAmountNet+feeAmountVat) FROM enquiries_custom_fees WHERE enquiries_custom_fees.enquiryRef = enquiries.id))) AS salesTotalEuros, (SELECT SUM(jobs_payments.amount) FROM jobs_payments WHERE currencyRef = 1 AND jobRef = jobs.id) AS paidAmountPounds, SUM(((SELECT SUM((quantity*(sellingNet+sellingVat))) FROM parts_trading WHERE parts_trading.enquiryRef = enquiries.id)+(SELECT SUM(feeAmountNet+feeAmountVat) FROM enquiries_custom_fees WHERE enquiries_custom_fees.enquiryRef = enquiries.id)-jobs_payments.amount)) AS balanceTotal FROM jobs LEFT JOIN jobs_payments ON jobs.id = jobs_payments.jobRef, enquiries, users, branches, entity_details, (SELECT currencyRef, SUM(amount) AS total FROM jobs_payments GROUP BY currencyRef) AS paidTotalsTable WHERE enquiries.traderRef = users.id AND jobs.enquiryRef = enquiries.id AND users.branchRef = branches.id AND enquiries.entityRef = entity_details.id AND entity_details.paymentTermsRef = 1 AND (SELECT SUM(quantity*(sellingNet+sellingVat)) FROM parts_trading WHERE parts_trading.enquiryRef = enquiries.id) != '' AND ((SELECT SUM((quantity*(sellingNet+sellingVat))) FROM parts_trading WHERE parts_trading.enquiryRef = enquiries.id)+(SELECT SUM(feeAmountNet+feeAmountVat) FROM enquiries_custom_fees WHERE enquiries_custom_fees.enquiryRef = enquiries.id)) != jobs_payments.amount AND ((SELECT SUM((quantity*(sellingNet+sellingVat))) FROM parts_trading WHERE parts_trading.enquiryRef = enquiries.id)+(SELECT SUM(feeAmountNet+feeAmountVat) FROM enquiries_custom_fees WHERE enquiries_custom_fees.enquiryRef = enquiries.id)-jobs_payments.amount) > 0 AND jobs.stateRef != 5") ; The problem is, is that 'paidAmountPounds' only shows the value of the first row in that quiery (£40, but should by much much more). Does any one know how I can fix this?
  14. Hi, I am trying to fetch a row in advance of the current one to find out if the next result is the same or not, and do something based on the outcome. I know how to do this with the old mysql functions like mysql_data_seek. What is the equivalent in PDO? I want the below sample to return row number 2, but it returns nothing no matter what number I set the offset to be. $readAhead = $resultParts->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_REL, 1) ; echo $readAhead['partNumber'] ; array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL) is set in my prepare statement.
  15. Hi, I have wondered if just one user should be used (e.g. root) for connecting to the database is the right way of doing things? (which is what I have always done). Would it be better to have a new user created in the privileges section in MySQL and have all operation/table access assigned appropriately for every single user that signs up? I would think that this would give a lot more security but would need a bit more work. What are your thoughts?
  16. Hi, Is it possible to make some kind of network/web traffic sniffer than can give you stats on how much p2p, mail etc etc traffic is going out your router? If so, does anyone know of any tutorials on the subject?
  17. Hi, I would like to be able to receive and emain on what pages users are getting 404 errors (or any other for that fact). I have the directive in my .htaccess to redirect missing pages to my custom 404.php page. However, despite trying a number of tutorial on how to get it to email me the url they tried to access, I can not get it to work. My code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Please Wait</title> <meta http-equiv="refresh" content="0; url=http://www.mysite.co.uk" /> </head> <body> <?PHP $ip = getenv ("REMOTE_ADDR"); $requri = getenv ("REQUEST_URI"); $servname = getenv ("SERVER_NAME"); $combine = $ip . " tried to load " ; $url = $servname . $requri ; $httpref = getenv ("HTTP_REFERER"); $httpagent = getenv ("HTTP_USER_AGENT"); $today = date("D M j Y g:i:s a T"); $message2 = "On $today, $combine:\n http://www.$url\n User Agent = $httpagent \n $httpref "; $to = "my.email@domain.com"; $subject = "404 Error Report"; $from = "From:no-reply@domain.com\r\n"; mail($to, $subject, $message2, $from); ?> </body> </html> I just get: On Mon Jan 16 2012 9:55:57 am UTC, 82.153.239.221 tried to load : http://www.www.mysite.co.uk/404.php User Agent = Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET4.0C; .NET CLR 2.0.50727; .NET CLR 3.5.30729)
  18. Hi, I have a page on my site where it shows classes taking place this month, next month, and the month after. The problem is, is that I have classes appearing a month earlier than they should be, here is my code: <?PHP include("dbconnect.php") ; for($i=0;$i<3;$i++) { $x = $i+1 ; $result = $dbh->prepare("SELECT id, className, classDate FROM classes WHERE classDate < DATE_ADD(NOW(), INTERVAL ? MONTH) AND (classDate > DATE_ADD(NOW(), INTERVAL ? MONTH) OR ? = 0) AND classDate > DATE_SUB(NOW(), INTERVAL 1 DAY) ORDER BY classDate ASC") ; $result->bindParam(1, $x, PDO::PARAM_INT) ; $result->bindParam(2, $i, PDO::PARAM_INT) ; $result->bindParam(3, $i, PDO::PARAM_INT) ; $result->execute() ; echo '<div class="classColumn">' ; if($i > 0) echo '<span class="cTitle">' . $month = date('F', strtotime(date("M", time()) . " +$i month")) . '</span>' ; else echo '<span class="cTitle">This month</span>' ; while($row = $result->fetch()) { echo '<div class="classBlock">' ; echo '<img src="' . 'cake-classes-logo.jpg" alt="' . '" width="64" height="64"/>' ; echo '<span class="classTitle">' . $row['className'] . '</span><br />' ; echo "</div>" ; } echo '</div>' ; } ?> I don't know if it is just the date titles not syncing up with the results i.e. the echo '<span class="cTitle">' . $month = date('F', strtotime(date("M", time()) . " +$i month")) . '</span>' ; bit.
  19. I was thinking after 5 or 10 minutes they are put on a BRB status, nothing would be more annoying than going for a piss and coming back to find yourself logged out, hence the 30 minutes.
  20. I thought of using exec to ping the users ip but not all users are pingable, is that statement true? If it really isn't possible, then an automatic timeout if the user does nothing for 30 minutes is the best method? What about HTML5 Sockets? Again though, not all browsers support HTML5
  21. Its for an AJAX chat application. I am struggling to come up with a reliable way on how to detect if a user has disconnected due to say a power outage etc, and not to rely on 'onBeforeUnload' and other similar functions (javascript).
  22. Is there a way to use PHP sockets to simply detect when a user has disconnected from your server? e.g. When the user arrives on the website/app, a socket connection is made and a flag set in the database indicating they are online, when they leave the socket disconnects and the flag is reset.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.