PHP - Counting Downloaded And Previewed Amont Belong To A Particular File In A Web Sit
hi...
Im developing a web site to store a audio and video songs and it enable to download the songs for users. most of features I have finished at the moment. I need to count download users amount in a song and also need to count how many users view it only. actually I dont have any idea to do it using php. so anyone can me give any idea how to do it. thanks in advance for your help.... [attachment deleted by admin] Similar Tutorialshi... Im developing a web site to store a audio and video songs and it enable to download the songs for users. most of features I have finished at the moment. I need to count download users amount in a song and also need to count how many users view it only. actually I dont have any idea to do it using php. so anyone can me give any idea how to do it. thanks in advance for your help.... actually im try to do similar this http://www.music.lk/....php?index=5938 please give me any idea to do it.. thanks again.... [attachment deleted by admin] Nevermind. Changed the following and it works: ->withHeader('Content-Disposition', 'attachment; filename="'.$name.'"') When downloading a file, the name of the file is 'report.csv' (it literally has single quotes around it so Window's does recognize it as a CSV file). I am obviously adding them, but I am not sure where. The workflow is browser requests from webserver, webserver performs cURL request to a second server, second server creates CSV file and returns it to webserver which returns it to browser client. My code is below (I removed some unrelated script for briefness, but should have all pertinent code). Do you see the culprit? Any recommendations on how to troubleshoot? Thanks
Browser Client $('#list-header').on('click', '.download-data', function() { window.location.assign("/api/query/trend?parameters=foo&Accept=csv"); }); Webserver $app->get('/api/query/trend', function(Request $request, Response $response) { $uri = $request->getUri(); $path = substr($uri->getPath(), 4); //Remove "/api" from uri return $this->serverBridge->proxy($request->withUri($uri->withPath($path)), $response); }); $c['serverBridge'] = function ($c) { return new \NotionCommotion\ServerBridge\ServerBridge( new \GuzzleHttp\Client([ 'base_uri' => $c['settings']['server']['scheme'].'://'.$c['settings']['server']['host'], 'headers' => ['X-NotionCommotion-Key' => $c['settings']['server']['key']], 'timeout' => 30, ]) ); }; class ServerBridge { private $httpClient; public function __construct(\GuzzleHttp\Client $httpClient){ $this->httpClient=$httpClient; //Must be configured with default path } public function proxy(\Slim\Http\Request $slimRequest, \Slim\Http\Response $slimResponse):\Slim\Http\Response { //Forwards Slim Request to another server and returns the updated Slim Response. //TBD whether this method should change urlencoded body if provided to JSON and change Content-Type header. //TBD whether this method should change not send Slim request to Guzzle, but instead create a new Guzzle request and apply headers as applicable. $body=$slimRequest->getBody(); $slimRequest=($contentType=$slimRequest->getContentType()) ?$slimRequest->withUri($slimRequest->getUri()->withHost($this->getHost(false))) //Change slim's host to API server! :$slimRequest->withUri($slimRequest->getUri()->withHost($this->getHost(false)))->withHeader('Content-Type', $contentType); //And also apply Content-Type $guzzleResponse=$this->httpClient->send($slimRequest); //Blacklist headers which should not be changed. TBD whether I should whitelist headers instead. $excludedHeaders=['Date', 'Server', 'X-Powered-By', 'Access-Control-Allow-Origin', 'Access-Control-Allow-Methods', 'Access-Control-Allow-Headers']; $headerArrays=array_diff_key($guzzleResponse->getHeaders(), array_flip($excludedHeaders)); foreach($headerArrays as $headerName=>$headers) { foreach($headers as $headerValue) { $slimResponse=$slimResponse->withHeader($headerName, $headerValue); } } return $slimResponse->withStatus($guzzleResponse->getStatusCode())->withBody($guzzleResponse->getBody()); } private function getHost(bool $includeSchema=true):string { $baseUri=$this->httpClient->getConfig()['base_uri']; return $includeSchema?$baseUri->getScheme().'://'.$baseUri->getHost():$baseUri->getHost(); } } API Server $app->get('/query/trend', function (Request $request, Response $response) { $dataObject = $this->trendService->query($request->getQueryParams()); $responder = new ResponseContent\ResponseContentCsv($response); return $responder->respond($dataObject); ); class ResponseContentCsv { protected $response; public function __construct(\Psr\Http\Message\ResponseInterface $response) { $this->response=$response; } public function respond($dataObject) { $stream = fopen('php://memory', 'w+'); //Use fputcsv() to write to stream $name='report.csv'; rewind($stream); return $this->response->withBody(new \Slim\Http\Stream($stream)) //->setOutputBuffering(false) ->withHeader('Content-Description', 'File Transfer') ->withHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0') //->withHeader('Content-Type', 'text/csv') ->withHeader('Content-Disposition', "attachment; filename='$name'") ->withHeader('Expires', '0') //->withHeader('Content-Length', $doc->size), ->withHeader('Pragma', 'public'); } } Edited May 5, 2019 by NotionCommotion Figured out what I was doing wrong Hi, I'm trying to display the products for a certain tag in the email for new order in wooCommerce. For example, I want that when a client buys a product with a certain tag, all the products that have that tag to be added automatically to the order email too. For now I achieved to display the tag in the email but not the products that have that tag. I don't know how get the products that belongs to that tag and add them to the cart to so I can display them in the email. Any help as small as it may be, it is very welcomed, please. I'm a bit stuck. I'm not very skilled in php... Thank you very much function email_products_per_tag( $order, $item ) { $items = $order->get_items(); foreach ( $items as $item ) { $terms = wp_get_post_terms( $item['product_id'], 'product_tag' ); foreach($terms as $term){ $term_names[] = $term->name; // Product tag Name // $item2 = 'product_tag'=> ; // not very sure about this line... } } } add_action( 'woocommerce_email_after_order_table', 'email_products_per_tag', 10, 4 ); Edited September 15, 2020 by cimita This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=310934.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=349338.0 I have a table in my database named order, and i want to count the quantity sold. i have the basic query already setup like: Code: [Select] $sql = "SELECT SQL_CALC_FOUND_ROWS deal.id, deal.title, deal.min_qty, deal.start_date, deal.end_date, deal.status, deal.secondary, count(o.id) as orders_cnt FROM deals as deal LEFT JOIN orders as o on o.d_id = deal.id WHERE start_date >= '".$beg."' AND start_date <= '".$end."' GROUP BY o.d_id, deal.id ORDER BY start_date LIMIT ".AwsPager::getCurrentIndex().", ".AwsPager::getLimit(); Which would theoretically work, but in the orders table, there is a column named quantity, and its those numbers that i need to add together and store in the array as orders_cnt.. any clue how i can do that? Hi im trying to make it so the time says how many hows left, not how many hours past. i have the right idea but it shows a negative number under "$time" $hours = number_format(($diffrence / 60 / 60)); $time = number_format(($hours - 24)); One more question to ask. I'm trying to do a count of total logins that have happened in the last 5 months including the current one so far. My users_logins table has the following structu users_id, session_id, login_date(datetime), last_activity(datetime). What the end result is going to be is: <tr> <td></td> <th scope="col"><?php echo date("M", strtotime("-4 month")); ?></th> <th scope="col"><?php echo date("M", strtotime("-3 month")); ?></th> <th scope="col"><?php echo date("M", strtotime("-2 month")); ?></th> <th scope="col"><?php echo date("M", strtotime("-1 month")); ?></th> <th scope="col"><?php echo date("M"); ?></th> </tr> <tr> <th scope="row">Logins</th> <td>94</td> <td>53</td> <td>124</td> <td>92</td> <td>105</td> </tr> Where the first td would be May and the last td would be September. Do I have to do this in 4 separate queries. If so here's what I have for the first query. I'm not sure what woudl go for the WHERE. $four_months_ago_query = "SELCT COUNT(date_login) FROM users_logins WHERE ? "; I'm trying to get a total number from the db where the month is the same and the ip is different. This is a stats script that someone else wrote, and I'm just trying to get a month-to-month total. Right now, it pulls the information out and displays the month with how many different ips came that month, the problem is, it lists like this: June - 41 - 41 June - 1 - 1 June - 1 - 1 June - 1 - 1 June - 1 - 1 June - 1 - 1 June - 9 - 9 June - 2 - 2 June - 2 - 2 June - 2 - 2 June - 1 - 1 June - 3 - 3 June - 2 - 2 June - 4 - 4 June - 1 - 1 June - 13 - 13 June - 154 - 154 what I need to do is grab all those numbers and give a total for that month, in this case, June. This is my query Code: [Select] $query = "SELECT date, COUNT(referrer)'referrer' FROM app_analytics WHERE appid = $userid AND date BETWEEN '" .$y_month . "' AND '" . $t_month . "' GROUP BY referrer ORDER BY date"; Can anybody help out? Thanks in advance I have a page that displays a list of retail locations (est. 100-150 locations). I have my layout setup to fit 3 columns side by side. Ex: <div class="col"></div> <div class="col"></div> <div class="col"></div> .. with the "col" class having a specific width and float: left. Basically, I want to print out the locations in the column and when a column reaches a certain number of locations, it closes that div and starts a new one and continues printing the rest of the locations. How would I go about making sure that once a column has reached a certain number of locations, it closes the div and starts the new one? ............. else if(empty($password)){ $errorMsg[]="please enter password"; } else { try { $select_stmt=$db->prepare("SELECT * FROM tbl_user WHERE username=:uname OR email=:uemail"); $select_stmt->execute(array(':uname'=>$username, ':uemail'=>$email)); $row=$select_stmt->fetch(PDO::FETCH_ASSOC); if($select_stmt->rowCount() > 0) { if($username==$row["username"] OR $email==$row["email"]) { if(password_verify($password, $row["password"])) { $_SESSION["user_login"] = $row["user_id"]; //---------------- $pdo_statement=$db->prepare("update tbl_user set logins=7 where user_id=2"); $result = $pdo_statement->execute(); //---------------- $loginMsg = "Successfully Login..."; header("refresh:2; welcome.php"); } else hey guys iam starting to learn during this crysis php :-). I got stucked with this pdo style..... i like to count logins, i tryed and figured out i can use the id... but my question is how can replace this "where user_id=2" to get the specific ID for the current user login in? the count function i i know how to make the... first i want to know how to write the syntax of this pdo...... thank you :-) Hello I have a table that inserts a new row with data when a member views a page. I wish to count all the rows for each member, and then be able to show what the cuurent members "position" is eg. what members has the highest row count. Example. counting the rows for member_A returns 1000 rows, the number of rows for member_B returns 1500 rows. How can I display for member_A that he is in "second" place? Hiya peeps, I have a mysql database with a record of all the images a customer uploads on my site, these images are displayed on there account. I can get this to work but the problem I'm facing is I need a minimum of 5 images displayed so if they only upload 2 images for instance I need to detect that and add my "No Image Uploaded" image. But if they have uploaded 5 or more I need to just let them be displayed without adding the "No Image Uploaded" picture. Does anyone have any ideas as I'm very stuck! Many thanks James. I have an array. When I print it it looks like this: Quote Array ( [1] => Array ( [Cushion] => Cushion 1 [Fabric] => f-111111 [FabricPrice] => 0 [Fill] => Fiber [Button] => none [ContWelt] => none [ContWeltFabric] => none [Zipper] => N [Quantity] => 2 [WeltSize] => [SKU] => c-111111 [Edge] => Knife [Cap] => N [Straps] => N [Hinged] => N [Type] => Boxed Button [Price] => 54.25 [Total] => 108.5 ) [2] => Array ( [Cushion] => Cushion 1 [Fabric] => f-111111 [FabricPrice] => 0 [Fill] => Fiber [Button] => none [ContWelt] => none [ContWeltFabric] => none [Zipper] => N [Quantity] => 4 [WeltSize] => [SKU] => c-111111 [Edge] => Knife [Cap] => N [Straps] => N [Hinged] => N [Type] => Boxed Button [Price] => 54.25 [Total] => 217 ) ) Now when I use count() I get a result of 01 when I should get 02 when I use count( ,1) I get a result of 381. I am Using this wrong? the array is stored in $_SESSION['cushArray'] I know how to count the files: <?php $dir = $_SERVER[DOCUMENT_ROOT]."/api/sigs/cache/".$i[id]."/"; $files = scandir($dir); $result = count($files); printf("$result Signatures Generated"); ?> But i'm trying to make it so it only counts the files that were modified recently (That Day). ok my code is below but i want to count how many $sname or ['member_name'] there is as if there is 4 or more i want it to add a marquee to it have that sorted but im having trouble getting it to count can you help me? $query = "SELECT * FROM `ibf_members` WHERE member_group_id = '4' or member_group_id = '6' or member_group_id = '17' or member_group_id = '18' or mgroup_others = '4' or mgroup_others = '6' or mgroup_others = '17' or mgroup_others = '18' "; $result99 = mysql_db_query("pbf99_backup", $query); $staff1 = mysql_num_rows($result99); if ($result99) { while ($r = mysql_fetch_array($result99)) { // Begin while $sid = $r["member_id"]; $smgid = $r["member_group_id"]; $query2 = "SELECT * FROM `ibf_sessions` WHERE member_id = '$sid'"; $result2 = mysql_db_query("pbf99_backup", $query2); if ($result2) { while ($r2 = mysql_fetch_array($result2)) { // Begin while $sname = $r2["member_name"]; $query3 = "SELECT * FROM `ibf_groups` where g_id = '$smgid'"; $result3 = mysql_db_query("pbf99_backup", $query3); if ($result3) { while ($r3 = mysql_fetch_array($result3)) { // Begin while $ssuffix = $r3["suffix"]; $sprefix = $r3["prefix"]; echo "<a href='$host$sid' target='_parent'>$sprefix$sname$ssuffix$stafff</a><br><br>"; }}}}}} ?> I am getting the result I expected with ORDER BY/GROUP BY queries WITH a troubling EXCEPTION: the data is being IN ORDER from 0 thru 9, but 10 (which in this test sample is my LARGEST quantity) is being inserted between the ONE and 2 quantity. Not sure if this will occur with ALL teen values, as well as hundreds. The column is a SMALLINT field (not sure if that makes a difference)> Is there a solution for this situation? Hello, I'm creating a program that analyzes information that is exported by another program. That program exports it in this way: Value1 Value2 Value3 Value4 Value1 Value2... In order to insert them in the database, I first have to know how many lines are inserted. They get send through HTML post. I already tried: $lines = explode("\n", $string); $number_lines = count($lines); But this always results in 1. How do I fix this? Regards, Chris 15 rows selected from the table. I want to randomly display an ad between them. Here's the code: Code: [Select] $count = 1; (mysql select rows) $number = rand (1,15); if ($count == $number) { echo 'ad code '; } $count++; I want the ad to be displayed only once and in the above code, depending on the generated number by rand() matching the $number the ads will be displayed more times. How can I limit this only to one? Hi everyone. I need to display a list of departments and a total of occurrences of each department in mysql/php. eg. There are 3 Administration types. There are 5 Government types. etc. there is no error when i run the code below, but nothing displays happens either. i'd appreciate anyone's help. Thanks. Code: [Select] <?php $query = mysql_query("SELECT CompanyName, CompanyBranch, DateRecorded, DateClosed, Year(DateRecorded) AS Year, CaseOwner.UsersDepartment FROM records LEFT JOIN CaseOwner ON CaseOwner = CaseOwner.ProperName GROUP BY CompanyName, CompanyBranch, DateRecorded, DateClosed, CaseOwner.UsersDepartment ORDER BY CaseOwner.UsersDepartment") or die("SELECT Error: ".mysql_error()); $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo "There are ". $row['COUNT(CaseOwner.UsersDepartment)'] ." ". $row['CaseOwner.UsersDepartment'] ." types."; echo "<br />"; } ?> |