Jump to content

mahogan

Members
  • Posts

    21
  • Joined

  • Last visited

mahogan's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I have a php script that saves both an svg and a png to my server. Currently it saves the SVG file to this folder: '/..saved-customer-files' It ALSO currently saves both the SVG and PNG file to this location: '../../customer-design-proofs/' The Problem: I need it to work opposite, save the SVG and PNG to: '/..saved-customer-files' And save Only the PNG to: '../../customer-design-proofs/' <?php require_once '../session.inc.php'; initSession(); if(!isset($_POST['output_svg']) && !isset($_POST['output_png'])) { die('post fail'); } $file = ''; $suffix = isset($_POST['output_svg'])?'.svg':'.png'; if(isset($_POST['filename']) && strlen($_POST['filename']) > 0) { //$file = $_POST['filename'] . $suffix; $un = UniqueName(); $_SESSION['name'] = $un; $file = $un . $suffix; } else { //$file = 'image' . $suffix; $un = UniqueName(); $_SESSION['name'] = $un; $file = $un . $suffix; } if($suffix == '.svg') { $mime = 'image/svg+xml'; $contents = rawurldecode($_POST['output_svg']); } else { $mime = 'image/png'; $contents = $_POST['output_png']; $pos = (strpos($contents, 'base64,') + 7); $contents = base64_decode(substr($contents, $pos)); } /* Sets Path for SVG file */ define('DIR_PATH_SVG', '../saved-customer-files/'); $fp = fopen(DIR_PATH_SVG.$file, 'w+'); $temp=fwrite($fp, $contents); /* Sets Path for PNG file */ define('DIR_PATH_PNG', '../../customer-design-proofs/'); $fp = fopen(DIR_PATH_PNG.$file, 'w+'); $temp=fwrite($fp, $contents); fclose($fp); if (isset($_POST['output_svg'])) { $svg_contents = $_POST['svg']; $pos = (strpos($svg_contents, 'base64,') + 7); $svg_contents = base64_decode(substr($svg_contents, $pos)); file_put_contents(DIR_PATH_SVG . $_SESSION['name'] . '.svg', $svg_contents); } if (isset($_POST['output_png'])) { $png_contents = $_POST['output_png']; $pos = (strpos($png_contents, 'base64,') + 7); $png_contents = base64_decode(substr($png_contents, $pos)); file_put_contents(DIR_PATH_PNG . $_SESSION['name'] . '.png', $png_contents); } function UniqueName() { $random_id_length = 10; $rnd_id = crypt(uniqid(rand(),1)); $rnd_id = strip_tags(stripslashes($rnd_id)); $rnd_id = str_replace(".","",$rnd_id); $rnd_id = strrev(str_replace("/","",$rnd_id)); $rnd_id = substr($rnd_id,0,$random_id_length); return $rnd_id; } ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title></title> </head> <body> <script> window.parent.svgEditor.savedFileName = '<?php echo $_SESSION['name']; ?>'; </script> </body> </html>
  2. I am very new to php and I have seen many posts on how to write to a csv file and several on how to fgetcsv data from a file, but none of it really makes sense and I cannot find a relevant example of what I am attempting to do. I know that most will say, use mySQL, but for this example, I really want to know how to use a csv as a data source. I have a php script that creates an image gallery from the folder that it is placed. It also gets and displays the embedded image attributes, filename, file dimensions, file size. Rather than display the file dimensions and file size, I want a corresponding csv file to display an image Category and other details from the csv. The full original php script can be viewed here: http://www.mahogan.com/gallery.txt The modified working model of this gallery can be viewed here: http://www.mahogan.com/sandbox/thumbs/gallery.php Here is a php script that gets the data from the csv: http://www.mahogan.com/sandbox/thumbs/gallery-fgetcsv.php echo "<html><body><table>\n\n"; $f = fopen("gallery-data.csv", "r"); while (($line = fgetcsv($f)) !== false) { echo "<tr>"; foreach ($line as $cell) { echo "<td>" . htmlspecialchars($cell) . "</td>"; } echo "<tr>\n"; } fclose($f); echo "\n</table></body></html>"; In my examples of the csv, this just prints the entire csv in an html table as in the file. What I do not understand is this: 1) How to Match the Filename with the thumbnail filename in the folder so that all the data in that row will stay with that filename. 2) How to assign/replace this csv data to print these in place of the image attributes. Any advice with using this CSV as a data source would be very appreciated as I really want to learn how to do this! Thanks!
  3. Well, I am at wits end with this... so if anyone is interested in some freelance work, I posted this project for hire, there are some additional factors to that of what I was working on here. https://www.freelancer.ph/projects/PHP-Javascript/Serif-WebPlus-integrate-php-script.html
  4. Ok, I was looking up online why the var_dump() function might be failing and I found this, not exactly sure if it is relevant: http://stackoverflow...ump-not-working So, I see with their issue, it was something to do with thier Ajax script. So I got to looking at my files, and wonder if this is helpful? Here is the my script that deals with Ajax getting the pricing data, this is located within a javascript section of my index page: //////////////////// GET APPLICABLE SIZE OPTIONS FOR SELECTED MATERIAL function sizeOptions(materialid) { //alert(materialid); if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById('sizeid').innerHTML=xmlhttp.responseText; additionalOptions(materialid); } } xmlhttp.open("GET","options.php?materialid="+materialid,true); xmlhttp.send(); } //////////////////// GET ADDITIONAL OPTIONS - DOUBLE SIDED & GROMMETS function additionalOptions(materialid) { //alert(materialid); if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById('radio').innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","additional_options.php?materialid="+materialid,true); xmlhttp.send(); } //////////////////// GET PRICES VIA AJAX function getPrices(materialid, sizeid, quantity, numcolors) { //alert("Materal ID: "+materialid+" Size ID: "+sizeid+" Quantity: "+quantity+" # of colors: "+numcolors); if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById('price').innerHTML=xmlhttp.responseText; } } document.getElementById('price').innerHTML="<p/ ><b>Getting price. Please wait....</b>"; xmlhttp.open("GET","price.php?materialid="+materialid+"&sizeid="+sizeid+"&quantity="+quantity+"&numcolors="+numcolors,true); xmlhttp.send(); } Not sure if this is helpful, if so please let me know. Thanks again!
  5. It still hangs at: Getting price. Here is the exact code that I have: <?php error_reporting(-1); include('simple_html_dom.php'); // Request parameters $materialid = $_GET['materialid']; $sizeid = $_GET['sizeid']; $quantity = $_GET['quantity']; $numcolors = $_GET['numcolors']; // form URL for request //$url = "http://www.suppliersite.com/pricing?materialid=104&sizeid=37&quantity=1&numcolors=1"; $url = "http://www.suppliersite.com/pricing?materialid=".$materialid."&sizeid=".$sizeid."&quantity=".$quantity."&numcolors=".$numcolors; // Create DOM from URL or file $html = file_get_html($url); // Echo page //echo $html->plaintext; //Code that creates $html echo "<pre>";var_dump ($html);die(); $price_per_item = $html->find('#price-per-item'); var_dump ($price_per_item); // $price_per_item = $html->find('#price-per-item'); $total_price = $html->find('#total-price'); $description = $html->find('.description'); $name = $html->find('h3'); //echo $price_per_item[0]."<br />"; //echo $total_price[0]."<br />"; //echo $description[0]."<br />"; //echo $name[1]."<br />"; // Iterate through all combinations: echo "<table id=\"products\">"; echo "<tr>"; //echo "<th>Price per item</th><th>Total Price</th><th>Product</th><th>Description</th><th>Size</th><th>Quantity</th>"; echo "<th width=\"25%\">Price per item</th><th width=\"15%\">Total Price</th><th width=\"30%\">Product</th><th width=\"10%\">Size</th><th width=\"10%\">Colors</th>"; echo "<tr>"; $price_per_item = $html->find('#price-per-item'); $total_price = $html->find('#total-price'); $description = $html->find('.description'); $size = $html->find('select[id='.'top-sizes-select'.'] option[value='.$sizeid.']'); echo"<tr>"; echo "<td>".$price_per_item[0]."</td>". "<td>".$total_price[0]."</td>". "<td>".$name[1]->innertext."</td>". // "<td>".$description[0]."</td>". "<td>".$size[0]->innertext."</td>". "<td>".$numcolors."</td>"; echo "</table>"; echo "<br />"; echo "<div style=\"width:40%\">"; echo $description[0]; echo "</div>"; ?> Is it possible that there is a security protocol from my supplier site that is preventing this from working?
  6. Maybe I misunderstood? To reiterate, I first started with my original code, then added this to line 2: error_reporting(-1); Then added what you suggested: //Code that creates $html $price_per_item = $html->find('#price-per-item'); var_dump ($price_per_item); The result is it will just hang at: Getting price. Please wait.... It does not show me any errors at this stage. So that is why I thought I would try something else, hence the errors shown in a previous post, but now that I know that is completly wrong, I won't go there again. So, I am not sure why it just hangs, I am at a loss. So am I misunderstanding something else?
  7. In the above post I did not have the error reporting in line 2, so I added it and here is the result: Notice: Use of undefined constant per - assumed 'per' in /homepages/mysite/price.php on line 26 Notice: Undefined variable: price in /homepages/mysite/price.php on line 26 Notice: Use of undefined constant item - assumed 'item' in /homepages/mysite/price.php on line 26 int(0) Line 26 is this: var_dump ($price-per-item);
  8. Ok, so I started fresh with my original file, added the var_dump // Create DOM from URL or file $html = file_get_html($url); // Echo page //echo $html->plaintext; //Code that creates $html $price_per_item = $html->find('#price-per-item'); var_dump ($price_per_item); $total_price = $html->find('#total-price'); $description = $html->find('.description'); $name = $html->find('h3'); It still hangs. So I thought I would see if I get a something if I change the variable to this (what the supplier id is: var_dump ($price-per-item); and it returns this: int(0) At this point, I'm really feeling kinda brain dead about this and am on the verge of hoping someone here does some affordable freelancing, but I really need to know how to make this happen.
  9. Perhaps I must be misunderstanding this as well, but I added this to the top of the code just under <?php error_reporting(-1); I still do not get any results, just hangs as before. I checked my server settings in my phpinfo report they are as follows: disable_functions no value no value display_errors On On display_startup_errors Off Off error_append_string no value no value error_log no value no value error_prepend_string no value no value error_reporting no value no value html_errors On On ignore_repeated_errors Off Off log_errors Off Off log_errors_max_len 1024 1024 track_errors Off Off xmlrpc_error_number 0 0 xmlrpc_errors Off Off Do I need to adjust some of these to get the error reporting working? If, so I need to call my host to adjust these settings. Or is it something else? On another note, not sure if this is relevant, but the php script in question does work along side another parser file: include('simple_html_dom.php'); However, I searched in this file for any relevant strings, etc and see nothing.
  10. Sorry for my confusion with this, and again, thank you for your patience and response. Unfortunately it does not seem to matter where I put the var_dump that you listed above, it seems to crash, where it just hangs with the message: "Getting price. Please wait...." Here is the code and where I added it: // Echo page //echo $html->plaintext; $price_per_item = $html->find('#price-per-item'); var_dump ($html->find('#price-per-item')); $total_price = $html->find('#total-price'); $description = $html->find('.description'); $name = $html->find('h3'); After that did not work, I removed it and added it here: echo "<tr>"; $price_per_item = $html->find('#price-per-item'); var_dump ($html->find('#price-per-item')); $total_price = $html->find('#total-price'); $description = $html->find('.description'); $size = $html->find('select[id='.'top-sizes-select'.'] option[value='.$sizeid.']'); echo"<tr>"; It still does the same thing, just hangs. When I view the source of my supplier site, it looks like this: </div> <ul class="clear pricing-summary"> <li>Price per Item <strong><span id="price-per-item">$11.55</span> each</strong></li> <li>Your total price<strong><span id="total-price">$11.55</span> total</strong></li> If it is a number or a string? I would say a string.
  11. I just dont get why the math does not work like this: $retail_per_item = $price_per_item * 1.2; I have been reading all kinds of instruction and posts on doing math in php and it seems so simple. I have tried countless attempts in varing places, yet this is so excruciatingly difficult! Argh!
  12. So I have tried a few things for the math but keep getting this error: Fatal error: Unsupported operand types in Line 43 42 // Attempt to define Markup Value of retail_per_item 43 $retail_per_item=$price_per_item*1.2; Here is all my modified code from where I changed it to the end: // ORIGINAL CODE $price_per_item = $html->find('#price-per-item'); // ORIGINAL CODE $total_price = $html->find('#total-price'); // ALTERED CODE next two lines only $price_per_item = preg_replace("#[^\d\.]#", '', $html->find('#price-per-item')); $total_price = preg_replace("#[^\d\.]#", '', $html->find('#total-price')); $description = $html->find('.description'); $size = $html->find('select[id='.'top-sizes-select'.'] option[value='.$sizeid.']'); // Attempt to define Markup Value of retail_per_item $retail_per_item=$price_per_item*1.2; var_dump ('$retail_per_item'); echo $retail_per_item; echo"<tr>"; // (Original Line, Altered 1 line below) echo "<td>".$price_per_item[0]."</td>". echo "<td>".$retail_per_item[0]."</td>". "<td>".$total_price[0]."</td>". "<td>".$name[1]->innertext."</td>". // "<td>".$description[0]."</td>". "<td>".$size[0]->innertext."</td>". "<td>".$numcolors."</td>"; echo "</table>"; echo "<br />"; echo "<div style=\"width:40%\">"; echo $description[0]; echo "</div>"; ?>
  13. Thank you so much for your patience and help! Okay, I think that must work, as I now see in the table just the number 11.55 with no $. So that must mean that it is a value. So where would I put the markup calculation, as no matter where I try to define it, it gives me an unexpected operand error? Then how do I get the $ sign back after the math?
  14. Could this be partially why this doesn't work? I found this similar situation: located here: http://php.net/manua...reg-replace.php If there's a chance your replacement text contains any strings such as "$0.95", you'll need to escape those $n backreferences: <?php function escape_backreference($x) { return preg_replace('/\$(\d)/', '\\\$$1', $x); } ?> If so, I would not know where to incorporate these either. I tried a few places, but without success.
  15. Honestly, I am very confused where to place the preg_replace() code exactly. Then I am not sure where to do the math markup. Here is what I have, with the preg_replace() in the existing code: <?php // Request parameters $materialid = $_GET['materialid']; $sizeid = $_GET['sizeid']; $quantity = $_GET['quantity']; $numcolors = $_GET['numcolors']; // form URL for request //$url = "http://www.suppliersite.com/pricing?materialid=104&sizeid=37&quantity=1&numcolors=1"; $url = "http://www.suppliersite.com/pricing?materialid=".$materialid."&sizeid=".$sizeid."&quantity=".$quantity."&numcolors=".$numcolors; // Create DOM from URL or file $html = file_get_html($url); // Echo page //echo $html->plaintext; $price_per_item = $html->find('#price-per-item'); $total_price = $html->find('#total-price'); $description = $html->find('.description'); $name = $html->find('h3'); //echo $price_per_item[0]."<br />"; //echo $total_price[0]."<br />"; //echo $description[0]."<br />"; //echo $name[1]."<br />"; // Iterate through all combinations: echo "<table id=\"products\">"; echo "<tr>"; //echo "<th>Price per item</th><th>Total Price</th><th>Product</th><th>Description</th><th>Size</th><th>Quantity</th>"; echo "<th width=\"25%\">Price per item</th><th width=\"15%\">Total Price</th><th width=\"30%\">Product</th><th width=\"10%\">Size</th><th width=\"10%\">Colors</th>"; echo "<tr>"; // ORIGINAL CODE $price_per_item = $html->find('#price-per-item'); // ORIGINAL CODE $total_price = $html->find('#total-price'); // ALTERED CODE next two lines only $price_per_item = preg_replace("#[^\d\.]#",$html->find('#price-per-item')); $total_price = preg_replace("#[^\d\.]#",$html->find('#total-price')); $description = $html->find('.description'); $size = $html->find('select[id='.'top-sizes-select'.'] option[value='.$sizeid.']'); echo"<tr>"; echo "<td>".$price_per_item[0]."</td>". "<td>".$total_price[0]."</td>". "<td>".$name[1]->innertext."</td>". // "<td>".$description[0]."</td>". "<td>".$size[0]->innertext."</td>". "<td>".$numcolors."</td>"; echo "</table>"; echo "<br />"; echo "<div style=\"width:40%\">"; echo $description[0]; echo "</div>"; ?>
×
×
  • 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.