Jump to content

Lassie

Members
  • Posts

    390
  • Joined

  • Last visited

Everything posted by Lassie

  1. I need to log when a customer downloads a purchase which could be multiple. My script is structured as follows:- First run through script read dir and create download links and display user can click link for download(s) If file selected Get the filename to be downloaded and download. increment download count compare with total files to be downloaded if equal, update db end session and exit. My problem is my counter is not accumulating the download count. Any guidance appreciated. if not equal files still avaialable for download # If a download has already been selected, #----------------------------------------- If ($_GET['file']){ # Get the filename to be downloaded #---------------------------------- $file = $_GET['file']; $file = stripslashes($file); $file = htmlspecialchars($file); $mainpath = "$path$file"; # Increment download count #------------------------- $filename = "./file_info/descriptions/$file.0"; $newfile = fopen($filename,"r"); $content = fread($newfile, filesize($filename)); fclose($newfile); $fileinfo = explode ("|",$content); $fileinfo[0] ++; # Save the new file count #------------------------ $content = implode("|", $fileinfo); $newfile = fopen($filename,"w"); fwrite($newfile, $content); fclose($newfile); # Translate file name properly for Internet Explorer #--------------------------------------------------- if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")){ $file = preg_replace('/\./', '%2e', $file, substr_count($file, '.') - 1); } # Make sure the file exists before sending headers #------------------------------------------------- if(!$fdl=@fopen($mainpath,'rb')){ die("Cannot Open File!"); } else { ini_set("zlib.output_compression", "Off"); # Send the headers then send the file #------------------------------------ header("Cache-Control: ");# leave blank to avoid IE errors header("Pragma: ");# leave blank to avoid IE errors header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"".$file."\""); header("Content-length:".(string)(filesize($mainpath))); sleep(1); fpassthru($fdl); $counter++; #this for debug purpose $to="@yahoo.co.uk"; $subject="counter count"; $msg="all files downloaded for folder $hash and counter equals $counter and files equals $_SESSION[num] and "; mail($to,$subject,$msg); if ($counter==$_SESSION[num]) { #this is where db code will go $to="@yahoo.co.uk"; $subject="download count"; $msg="all files downloaded for folder $hash"; mail($to,$subject,$msg); $counter=0; } }
  2. I have a download script that was working and now is not. Is there any addition I can make to the script to debug this. I added the following line to make the download work and this is still there but no download when the file link is clicked. The code that made it work was ini_set("zlib.output_compression", "Off"); the relevant part of the script is # If a download has already been selected, #----------------------------------------- If ($_GET['file']){ # Get the filename to be downloaded #---------------------------------- $file = $_GET['file']; $file = stripslashes($file); $file = htmlspecialchars($file); $mainpath = "$path$file"; # Increment download count #------------------------- $filename = "./file_info/descriptions/$file.0"; $newfile = fopen($filename,"r"); $content = fread($newfile, filesize($filename)); fclose($newfile); $fileinfo = explode ("|",$content); $fileinfo[0] ++; # Save the new file count #------------------------ $content = implode("|", $fileinfo); $newfile = fopen($filename,"w"); fwrite($newfile, $content); fclose($newfile); # Translate file name properly for Internet Explorer #--------------------------------------------------- if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")){ $file = preg_replace('/\./', '%2e', $file, substr_count($file, '.') - 1); } # Make sure the file exists before sending headers #------------------------------------------------- if(!$fdl=@fopen($mainpath,'rb')){ die("Cannot Open File!"); } else { ini_set("zlib.output_compression", "Off"); # Send the headers then send the file #------------------------------------ header("Cache-Control: ");# leave blank to avoid IE errors header("Pragma: ");# leave blank to avoid IE errors header("Content-type: application/force-download"); header("Content-Disposition: attachment; filename=\"".$file."\""); header("Content-length:".(string)(filesize($mainpath))); sleep(1); fpassthru($fdl); $counter++; $to="@yahoo.co.uk"; $subject="counter count"; $msg="all files downloaded for folder $hash and counter equals $counter and files equals $_SESSION[num] and "; mail($to,$subject,$msg); if ($counter==$_SESSION[num]) { $to="@yahoo.co.uk"; $subject="download count"; $msg="all files downloaded for folder $hash"; mail($to,$subject,$msg); $counter=0; } }
  3. I am trying to debug my download script and keep getting the php code displayed in the browser but I cant work out why. The code is 500 lines so I have only posted the code from thepoint where it displays in th browser. Any pointers welcome. # Pagination Start. #------------------ if ($records_per_page < 1) { $records_per_page = $totalfiles + 1; } if ($totalfiles > $records_per_page) { $totalpages = ceil($totalfiles/$records_per_page); $flag = 0; if ($currentpage > $totalpages) { $currentpage = 1; } }ELSE { $flag = 1; } include_once('./includes/form_header.php'); # Start main loop. #----------------- if ($match > 0) { while (list ($key, $val) = each ($filename)) { if ($key >= ($records_per_page-$records_per_page)+(($currentpage-1)*$records_per_page) && $key <= ($records_per_page-1)+(($currentpage-1)*$records_per_page)) { $fileattr = explode("|", $val); # Fix and format Byte Length #--------------------------- if ($fileattr[4] < pow(2,10)){ $size = "$fileattr[4] B"; } if ($fileattr[4] >= pow(2,10) && $fileattr[4] < pow(2,20)) { $size = round($fileattr[4] / pow(2,10), 2)." KB"; } if ($fileattr[4] >= pow(2,20) && $fileattr[4] < pow(2,30)) { $size = round($fileattr[4] / pow(2,20), 2)." MB"; } if ($fileattr[3] > pow(2,30)) { $size = round($fileattr[4] / pow(2,30), 2)." GB"; } # Alternate colors between white and grey (or black and grey) on table entries. #------------------------------------------------------------------------------ if ($color == $color1){ $color = $color2; }ELSE{ $color = $color1; } # Get correct icon file depending on file extention. #--------------------------------------------------- $ext = substr ($fileattr[3], 1, 3); $ext = (strtolower($ext)); $iconfile = "./file_info/thumbs/th_$fileattr[2]"; $nw = 100; $nh = 64; $xtrainfo = "Jpeg image "; if (($ext == "jpg") && (!file_exists($iconfile)) && ($gdlib == 1)) { $ht = thumbnail("$path$fileattr[2]",$thumbsize,"./file_info/thumbs/","th_$fileattr[2]"); } # Get the correct icon file if image exists with same name as filename. #---------------------------------------------------------------------- if (($ext <> "jpg") or ($gdlib == 0)){ $xtrainfo = "$ext file"; $iconfile = "file_info/icons/$icons/x.gif"; $iconfile1 = "file_info/icons/$icons/$ext.gif"; $iconfile2 = "file_info/thumbs/th_$fileattr[1].jpg"; $nw = 64; $nh = 64; if (file_exists($iconfile1)) { $iconfile = $iconfile1; } if (file_exists($iconfile2)) { $iconfile = $iconfile2; } } include_once('./includes/display_output.php'); } } #------------------------------------------------------------------------------------- # End main loop. include_once('./includes/Footer.php'); ?>
  4. I ahve a download script that is only downloading a fraction of the file. can anyone point me to a tutorial/script that will enable me to understand headers and what is required. Thank you.
  5. Thank you for your suggestion. I now download zero bytes. To add some clarity I am posting some of what I think is relevant code. I still have no print out of the $mainpath.Is my code OK to echo it as follows? # Send the headers then send the file #------------------------------------ header("Cache-Control: ");# leave blank to avoid IE errors header("Pragma: ");# leave blank to avoid IE errors header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"".$file."\""); header("Content-length:".(string)(filesize($mainpath))); header("Content-length:".(string)(filesize($$filename))); sleep(1); fpassthru($fdl); echo '(filesize[$mainpath]})'; echo '(filesize[$filename]})'; } variable set at start. $path = './'; $path = $path.$hash; # Read current directory. #------------------------ $d = opendir($path); while (false !== ($file = readdir($d))) { if ($file != "." && $file != "..") { # Get all the file attributes. #----------------------------- $size = filesize("$path$file"); $type = filetype("$path$file"); $ext = strrchr("$path$file",'.'); $modified = stat("$path$file"); $displayname = str_replace (strrchr ($file, "."), "", $file); # If the file does exist, read its data. #--------------------------------------- $newfile = fopen($filedescription,"r"); $content = fread($newfile, filesize($filedescription)); fclose($newfile); } $data = explode("|", $content); $accesses = $data[0]; $upload_date = $data[3]; # Start main loop. #----------------- if ($match > 0){ while (list ($key, $val) = each ($filename)) { if ($key >= ($records_per_page-$records_per_page)+(($currentpage-1)*$records_per_page) && $key <= ($records_per_page-1)+(($currentpage-1)*$records_per_page)){ $fileattr = explode("|", $val); # Fix and format Byte Length #--------------------------- if ($fileattr[4] < pow(2,10)){ $size = "$fileattr[4] B"; } if ($fileattr[4] >= pow(2,10) && $fileattr[4] < pow(2,20)) { $size = round($fileattr[4] / pow(2,10), 2)." KB"; } if ($fileattr[4] >= pow(2,20) && $fileattr[4] < pow(2,30)) { $size = round($fileattr[4] / pow(2,20), 2)." MB"; } if ($fileattr[3] > pow(2,30)) { $size = round($fileattr[4] / pow(2,30), 2)." GB"; } # Alternate colors between white and grey (or black and grey) on table entries. #------------------------------------------------------------------------------ if ($color == $color1){ $color = $color2; }ELSE{ $color = $color1; } # Get correct icon file depending on file extention. #--------------------------------------------------- $ext = substr ($fileattr[3], 1, 3); $ext = (strtolower($ext)); $iconfile = "./file_info/thumbs/th_$fileattr[2]"; $nw = 100; $nh = 64; $xtrainfo = "Jpeg image "; if (($ext == "jpg") && (!file_exists($iconfile)) && ($gdlib == 1)){ $ht = thumbnail("$path$fileattr[2]",$thumbsize,"./file_info/thumbs/","th_$fileattr[2]"); } # Get the correct icon file if image exists with same name as filename. #---------------------------------------------------------------------- if (($ext <> "jpg") or ($gdlib == 0)){ $xtrainfo = "$ext file"; $iconfile = "file_info/icons/$icons/x.gif"; $iconfile1 = "file_info/icons/$icons/$ext.gif"; $iconfile2 = "file_info/thumbs/th_$fileattr[1].jpg"; $nw = 64; $nh = 64; if (file_exists($iconfile1)) { $iconfile = $iconfile1; } if (file_exists($iconfile2)) { $iconfile = $iconfile2; } } /* if ($admin){ $admininfo = "<a href=\"./file_info/admin/edit.php?file=$fileattr[2]\" onClick=\"popup = window.open('./file_info/admin/edit.php?file=$fileattr[2]', 'PopupPage', 'height=350,width=520,scrollbars=yes,resizable=yes'); return false\" target=\"_blank\">Click Here to edit this entry</a><br>"; } */ # Print html results. #--------------------
  6. Thanks for the advice. I have tried your suggestion but I get no print output. I am not certain that I have coded this correctly but I will post the code so that you might venture an opinion. Thanks # Send the headers then send the file #------------------------------------ header("Cache-Control: ");# leave blank to avoid IE errors header("Pragma: ");# leave blank to avoid IE errors header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"".$file."\""); header("Content-length:".(string)(filesize($mainpath))); sleep(1); fpassthru($fdl); echo '(filesize[$mainpath]})'; }
  7. I have modified a download program to suit my purposes, and it essentailly works except I only get the first 1Kb regardless of file type. Below is the download section of the code. Where should I look for the problem?Is there anything in this code that would produce that type of result? # If a download has already been selected, #----------------------------------------- If ($_GET['file']){ # Get the filename to be downloaded #---------------------------------- $file = $_GET['file']; $file = stripslashes($file); $file = htmlspecialchars($file); $mainpath = "$path$file"; # Increment download count #------------------------- $filename = "./file_info/descriptions/$file.0"; $newfile = fopen($filename,"r"); $content = fread($newfile, filesize($filename)); fclose($newfile); $fileinfo = explode ("|",$content); $fileinfo[0] ++; # Save the new file count #------------------------ $content = implode("|", $fileinfo); $newfile = fopen($filename,"w"); fwrite($newfile, $content); fclose($newfile); # Translate file name properly for Internet Explorer #--------------------------------------------------- if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")){ $file = preg_replace('/\./', '%2e', $file, substr_count($file, '.') - 1); } # Make sure the file exists before sending headers #------------------------------------------------- if(!$fdl=@fopen($mainpath,'r')){ die("Cannot Open File!"); } else { # Send the headers then send the file #------------------------------------ header("Cache-Control: ");# leave blank to avoid IE errors header("Pragma: ");# leave blank to avoid IE errors header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"".$file."\""); header("Content-length:".(string)(filesize($mainpath))); sleep(1); fpassthru($fdl); } }else{ # GD Library thumbnail function. #------------------------------- function thumbnail($i,$nw,$p,$nn) { $img=imagecreatefromjpeg("$i"); $ow=imagesx($img); $oh=imagesy($img); $scale=$nw/$ow; $nh=ceil($oh*$scale); $newimg=imagecreateTrueColor($nw,$nh); imagecopyresized($newimg,$img,0,0,0,0,$nw,$nh,$ow,$oh); imagejpeg($newimg, $p.$nn); $heigth = $nh; return ($heigth); }
  8. Right I follow you.I am running on widows. Thanks.
  9. I will look into those. Thanks What is cron?
  10. I have a shopping cart application that stores a customers purchases in a specific directory made available for download via clicking on a link. I would like to destroy the directory ( and purchases) within once a customer has made the download. Could anyone suggest in principle, how to approach this. For example can the directory be set by a timescale to self destruct or can a download of a file be detected to trigger such an event.
  11. Thanks for coming back. It is now working. I'm not sure what was wrong but I may not have saved the changes I made to the code. Sorry to bother everyone.
  12. The problem is that when I test for the array as follows $review= get_book_reviews($product_id); if (!is_array($review)) { echo '<br />No reviews currently available for this book<br />'; } It returns negative, so no array. I am also not sure I have coded my foreach loop properly.
  13. I have a simple programme to retrieve book reviews. My query on the db works but I have an invaliid foreach arguement. The code is <?php include ('book_sc_fns.php'); // The shopping cart needs sessions, so start one session_start(); require_once ('./reg/includes/config.inc.php'); $product_id = $_GET['product_id']; $review= get_book_reviews($product_id); if (!is_array($review)) { echo '<br />No reviews currently available for this book<br />'; } else { //display //create table echo '<table width = \"700\" border = 0 align="center">'; foreach ($review as $row) { echo '<tr><td>'; echo $row['product_desc']; echo '</td>'; echo '<tr><td>'; echo $row['review']; echo '</td>'; echo '</tr>'; } echo '</table>'; } ?> the functions called are function get_book_reviews($product_id) { // query database for all reviews for a particular book if (!$product_id || $product_id=='') return false; $connection = db_connect(); $query= "SELECT * FROM book_reviews WHERE product_id= '$product_id'"; $result = mysql_query($query); $result = db_result_to_array($result); /* Debug to check query echo '<pre>'; print_r ($result); echo '</pre>'; */ if (!$result) return false; $review=$result; return $review; } function db_result_to_array($result) { $res_array = array(); for ($count=0; $row = mysql_fetch_assoc($result); $count++) $res_array[$count]=$row; return $res_array; } Any help appreciated
  14. I am trying to link my cart to paypal. I have successffully done this passing the total value of the cart. I now want to pass the individual line items and prices. These are required to be passsed as form variables. These are in the form of item_name_1 amount_1 item_name_2 amount_2 etc for all the items in the cart. For this I have the following function. function display_pp_form($name,$email, $Cheque = true) { ?> <table border = 0 width = '700' cellspacing = 0 align = center> <tr><th colspan = 2 bgcolor="#cccccc">Thank you <?php echo "$name";?></br>"If you wish to pay by CREDIT CARD please click on the the PayPal logo and you will be transferred to a secure processing center.</br> If you wish to pay by CHEQUE, please choose the cheque button.</br> </th></tr> <tr><td> <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="upload" value="1"> <input type="hidden" name="business" value="tina@hawkesleypublishing.com"> <?php $fld_idx = 1; foreach ($cart as $product_id => $qty) { $book = get_book_details($product_id); echo '<input type="hidden" name="item_name_' . $fld_idx . '" value="' . $book["title"] . '">'; echo '<input type="hidden" name="amount_' . $fld_idx . '" value="' . $book["price"] . '">'; $fld_idx++; } ?> <input type="hidden" name="currency_code" value="GBP"> <input type="hidden" name="amount" value="<?php echo $_SESSION['total_price'] ?>"> <input type="hidden" name="custom" value="<?php echo $name ?>"> //<input type="hidden" name="email" value="<?php echo $email ?>"> <input type="image" src="images/paypal.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!" align="center"> </form> The problem is that I get an invalid argument error and no values are passed to the paypal site. Warning: Invalid argument supplied for foreach() in c:\easyserv\www\e_cart12\display_fns.php on line 500 How can I debug the form?
  15. Thank you. Very elegant. I guess I can include this code in the form rather than passing any values to the function. That is the code would be included in the function. Is that right?
  16. I have a requirement to enter values in a form in the following format. <input type="hidden" name="item_name_1" value="Item_name_1"> <input type="hidden" name="amount_1" value="1.00"> <input type="hidden" name="item_name_2" value="Item_name_2"> <input type="hidden" name="amount_2" value="2.00"> In my application the item name = $title and amount=$price I have code which extracts the title and price but I cant figure out how increment the item_name_x and amount_x by 1, starting from 1, for each item purchased. My code sofar is:- $book = array(); foreach ($cart as $product_id => $qty) { $book[] = get_book_details($product_id); } $book_list =""; foreach($book as $single_book) { extract($single_book); $item_name_1=$title; $amount_1=$price; } echo"$item_name_1"; echo"$amount_1"; display_pp_form($name,$email); I ned to pass the values of item and amount to the display_pp_form function. Any ideas appreciated.
  17. Yes there is more code and looking at it I have found the missing brace. Thanks guys
  18. I have an error I cant solve at the conclusion of my script. any pointers appreciated. error is on last line as follows:- Parse error: parse error, unexpected $ in c:\easyserv\www\e_cart11\cheque_2.php on line 76 $book = array(); foreach ($cart as $product_id => $qty) { $book[] = get_book_details($product_id); } $book_list =""; foreach($book as $single_book) { extract($single_book); $book_list.=$title." by ".$author."\n"; } $to = "$email"; $subj = "test"; $mess = "<html>\n" ."<head>\n" ."<title>Test Mail</title>\n" ."</head>\n" ."<body>\n" ."This is an html email test<br />\n" ."<p><b>Your order has been processed. Please print this email as your reference</b></p>\n" ."<p>Your purchases were:-\n" .$book_list."</p></body>\n</html>\n"; $mess = wordwrap($mess,70); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; mail($to,$subj,$mess,$headers); display_cart($_SESSION['cart'], false, 1); //empty shopping cart session_destroy(); echo '<div id="cheque">'; echo '<p>Thank you for shopping with us.</br> Your order has been placed.</p></div>'; echo '</br></br>'; display_button('index.php', 'continue-shopping', 'Continue Shopping'); // display_button ('pick_up.php','b_buy','Pick Up Purcahse'); echo '</br></br>'; do_html_footer(); ?>/*error line*/
  19. Thanks> Cured that but now get parse error 'unepected $ on line 78. $to = "$email"; $subj = "test"; $mess = "<html>\n" ."<head>\n" ."<title>Test Mail</title>\n" ."</head>\n" ."<body>\n" ."This is an html email test<br />\n" ."<p><b>Your order has been processed. Please print this email as your reference</b></p>\n" ."<p>Your purchases were:-\n" .$book_list."</p></body>\n</html>\n"; $mess = wordwrap($mess,70); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; mail($to,$subj,$mess,$headers); display_cart($_SESSION['cart'], false, 1); //empty shopping cart session_destroy(); echo '<div id="cheque">'; echo '<p>Thank you for shopping with us.</br> Your order has been placed.</p></div>'; echo "</br></br>"; display_button('index.php', 'continue-shopping', 'Continue Shopping'); // display_button ('pick_up.php','b_buy','Pick Up Purcahse'); echo "</br></br>"; do_html_footer(); ?>/*parse error unexpected $*/
  20. Thanks. That cleared that but I now have a parse error in the email. Is it the "" again? Could you tell me something a out when to use "" or point me to a tutorial? Many thanks. $to = "$email"; $subj = "test"; $mess = "<html>\n" ."<head>\n" ."<title>Test Mail</title>\n" ."</head>\n" ."<body>\n" ."This is an html email test<br />\n" ."<p><b>Your order has been processed. Please print this email as your reference</b></p>\n" ."<p>Your purchases were:-\n" [b]."$book_list"</p>"[/b] ."</body>\n</html>\n";/*parse error*/ $mess = wordwrap($mess,70); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; mail($to,$subj,$mess,$headers);
  21. Thanks for that. I now get these errors:- Warning: Unexpected character in input: '\' (ASCII=92) state=1 in c:\easyserv\www\e_cart11\cheque_2.php on line 42 Parse error: parse error, unexpected T_STRING in c:\easyserv\www\e_cart11\cheque_2.php on line 42 I expect this is the "" not being correct. Is there a rule for this circumstance?
  22. Many thanks for your help, but I now get a parse error and I cant see why. $book = array(); foreach ($cart as $product_id => $qty) { $book[] = get_book_details($product_id); } $book_list =""; foreach($book as $single_book) { extract($single_book) $book_list.=$title." by ".$author\n";/*parse error*/? } $to = "$email"; $subj = "test"; $mess = "<html>\n" ."<head>\n" ."<title>Test Mail</title>\n" ."</head>\n" ."<body>\n" ."This is an html email test<br />\n" ."<p><b>Your order has been processed. Please print this email as your reference</b></p>\n" ."<p>Your purchases were:-\n" ."$book_list"</p>" ."</body>\n</html>\n"; $mess = wordwrap($mess,70); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; mail($to,$subj,$mess,$headers);
  23. I have an e-cart application and need to email a reciept of purchases. My email will only send/display the last set of purchases. ie if two items are purchased only the detail of item 2 is sent in the email. The code use a function to retrieve the product info and then I use extract to create variables to be referenced in the email. Have I gone about this the wrong way? foreach ($cart as $product_id => $qty) { $book = get_book_details($product_id); } extract($book); $to = "$email"; $subj = "test"; $mess = "<html>\n" ."<head>\n" ."<title>Test Mail</title>\n" ."</head>\n" ."<body>\n" ."This is an html email test<br />\n" ."<p><b>Your order has been processed. Please print this email as your reference</b></p>\n" ."<p>Your purchases were:- $title by $author </p>\n"(Only gives last item) ."</body>\n</html>\n"; $mess = wordwrap($mess,70); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; mail($to,$subj,$mess,$headers);
×
×
  • 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.