PHP - Order By File Modification Time
I have a table in my database which stores lot of file names & file path. iam currently listing the files on the basis of its uploaded date (stored in databse) but I want to list it on the basis of its file modification time.
How i can do it ?? my current sql statement is Code: [Select] $sql = mysql_query("SELECT * FROM `files` WHERE `cid` = '$types' ORDER BY `uploaded` DESC LIMIT $start,$limit"); anyone can help me ?? Similar TutorialsHello Coder Guys, I need a small help from you. I want to list all files & directories based on last file modification time of server. I want to list new files as first & old files as last. Consider "files" as the directory name which contains all files & directories. Please make the php code to display all files & directories from "files" directory based on last file modification time of server. Thanks IN Advance ! My DB is holding time as "11:00 AM" "10:00 AM" ect... Is there a way to convert these to time() after I have queried the DB for results? <?php connect(); $query = "SELECT * FROM party WHERE year(DOP) = '2011' order by PTIMES asc"; $qt=mysql_query($query); echo mysql_error(); while($nt=mysql_fetch_array($qt)){ echo " <tr height='30'> <td id='label'>".$nt['NOC']."</td> <td id='labeloff'>".$nt['CFN']." ".$nt['CLN']."</td> <td id='labeloff'>".$nt['type']."</td> <td id='label'>".birthday($nt['DOB'])."</td> <td id='label'>$DOP</td> <td id='labeloff'>".$nt['PTIME']."</td> <td id='labeloff'>".$nt['act1']."</td> <td id='labeloff'>".$nt['act2']."</td> <td id='label'>".$nt['pizza']."</td> <td id='label'>".$nt['fc']."</td> </tr> "; }free($qt); ?> Thank you. Hello.. I'm a somewhat beginner in php, but i decided to create my own basic forums system with a content managing system. Right now I'm trying to figure out how to make a thread link be at the top of the list for the forum display page, when someone posts a response or creates a new thread. HELP MUCH APPRECIATED Hi, I'm not necessarily looking for code examples for my problem, (they are welcome but its not my explicit goal). I'm looking more for advice on how to go about tackling the problem i have. what i already have Currently i have a search getting results from a MySQL database. The results are ordered by one field that signifies their importance. Many of these results have the same value in this one column, and i have a switch statement to distinguish different content/styles for the different values. (there are just over 10 different bands) So the most important results are shown first and with a different style to the ones below it. (some bands have the same styling) what i need I would like to be able to randomize the results but only randomize the results within their specified bands. e.g. lets say theres 100 results in band A and 100 in band B. I still want everything in band A to be listed above band B, but i would like to randomly change the order of the results in band A and band B, (in this case once a week). I need to save the order of this randomization (client/server side?) for a week, then run the script again to set a new order. Now I would still class myself as an amateur php'er so at this stage i dont even know how i would go about separating the bands and randomizing their results independantly, let alone causing this functionality to run only once a week. So can anyone suggest a way i might go about this? I'm pretty stuck right now. Cheers Hi, I'm inserting hours and minutes per user into a database where they have their own fields. (userid, hours, mins) I've a small issue when displaying the data. When I run my query I sum the total hours and minutes per user which results in data such as the following userid1 - 2 hours 15 mins userid2 - 1 hour 100 mins The query orders by hours and then mins desc When I'm displaying the data (as I'm looping through the results array) I perform a calculation to convert the mins to hours so it now reads userid1 - 2 hours 15 mins userid2 - 2 hours 40 mins so the webpage displays userid1 first when i want userid2 to be the first record displayed (Hours desc) Can anyone recommend a solution to this ? Will I need to create another table and update it as hours and minutes are being entered and display results from that table instead ? Can I order the data after I carry out the mins to hours calculation ? many thanks in advance for any suggestions.... tmfl Right now I am displaying a list of files in a dir. the files do not output in any type of order I would like them to display either alphabetically or by upload date. I have posted my code below any help would be great. <table border=0><tr><td align=center><b>File</b></td><td><b>Remove</b></td></tr> <?php $remove = $_GET[remove]; $dir = "/home/public_html/upload/files/"; $remove = $dir."".$remove; if($remove != "/home/public_html/upload/files/") {unlink($remove);} // Open a known directory, and proceed to read its contents if (is_dir($dir)) { if ($dh = opendir($dir)) { $color = "gray"; while (($file = readdir($dh)) !== false) { if($color == "gray") { $color = "black"; } elseif($color == "black") { $color = "gray"; } if(filetype($dir . $file) == "file") { echo "<tr bgcolor=$color><td><a href='../upload/files/$file'>$file</a></td><td align=center><a href='?remove=$file'>X</a></td></tr>"; } } closedir($dh); } } ?> </table> I'm looking to order my upload files in a specific order. I believe the default is a random upload order, but I would like to change this based on the file name, which I'm having difficulty with.
The file names would be for example;
'01 smiley' '02 dog' '03 cat'Currently I used a 'Drag & Drop' multiple file upload although this just uploads in any random order to my database table, I'd like to upload it by numeric order as above. Code so far (upload code works, just the order needs work)... $count = count($_FILES['upload']['name']); $in=0; while($in<$count) { //upload here $in++; }I think I need to sort()? before my while loop, but having difficulty getting this correct. How would I be able to sort each file into a correct order. Many thanks. Edited by Veltu, 12 December 2014 - 05:46 AM.
Hi everyone. I'm very new into self learning programming. Presently I'm trying to develop a simple basic Robot that would only Place a Market Order every seconds and it will cancel the Order every followed seconds. Using the following library: It would place Trade Order at a ( Price = ex.com api * Binance api Aggregate Trades Price) I have already wrote the api to call for xe.com exchange rate with php <?php $auth = base64_encode("username:password"); $context = stream_context_create([ "http" => [ "header" => "Authorization: Basic $auth" ] ]); $homepage = file_get_contents("https://xecdapi.xe.com/v1/convert_from?to=NGN&amount=1.195", false, $context ); $json = json_decode($homepage, TRUE); foreach ($json as $k=>$to){ echo $k; // etc }; ?> And also for the Binance Aggregate Price in JavaScript
<script> var burl = "https://api3.binance.com"; var query = '/api/v3/aggTrades'; query += '?symbol=BTCUSDT'; var url = burl + query; var ourRequest = new XMLHttpRequest(); ourRequest.open('GET',url,true); ourRequest.onload = function(){ console.log(ourRequest.responseText); } ourRequest.send(); </script>
My problem is how to handle these two api responds and also the functions to use them to place a trade and cancel it. I need to write a bit of code to select some mp3's (actually, just the titles) from a database...but I need to select them based on last play (which is a timestamp field in the DB) AND I need to select 14 minutes worth of them (and not more than 15 minutes). I currently do NOT know how long each song is... So, if every song was 2 minutes long, I would need 7 songs. If each song was 3 minutes long, I'd need to select 5 of them. I currently do NOT have a length field in the db (the boss sprung this on me after I designed the DB). A few questions: Would it be best to have a column of TIME (mysql time...not the name of the column)? Would it be best to have a column for the raw size of the file (each file is the same bitrate, so I could do the math - plus it would be probably be easier to import raw filesize using php into the db) Would it be easier to do something else? Once we answer that, I'll start with some code...and probably be back for help! I wrote a very simple web form that allows my user to view text files from within their Internet browser. Occasionally, the search criteria entered returns more than one file. So I want to implement a feature whereby the text files returned by the search are compressed into a ZIP. I got a prototype working but it only compresses the first file. The second or third files are ignored. Here's my code Code: [Select] <HTML><body><form name="myform" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <fieldset><label for="DBRIDs">RIDs</label><input type="text" id="DBRIDs" name="DBRIDs" > </fieldset></form></body></HTML> <?php function check_search() { if (isset($_POST['submit'])) {if (!empty($_POST['DBRIDs'])) { $results = getFiles(); } } else $errors = "Please enter something before you hit SUBMIT."; return Array($results, $errors); } function getFiles() { $result = null; $ZIPresult = null; if (empty($_POST['DBRIDs'])) { return null; } $mydir = MYDIR; $dir = opendir($mydir); $DBRIDs = $_POST['DBRIDs']; $getfilename = mysql_query("select filename from search_table where rid in (" . $DBRIDs . ")") or die(mysql_error()); while ($row = mysql_fetch_array($getfilename)) { $filename = $row['filename']; $result .= '<tr><td><a href="' . basename($mydir) . '/' . $filename . '" target="_blank">' . $filename . '</a></td></tr>'; $ZIPresult .= basename($mydir) . '/' . $filename; } if ($result) { $result = "<table><tbody><tr><td>Search Results.</td></tr> $result</table>"; shell_exec("zip -9 SearchResult.zip ". $ZIPresult ." > /dev/null "); } return $result; } The hyperlinks pointing to the file(s) are generated just fine. The ZIP file however only contains the first file listed in the results. How can I get the ZIP file to capture ALL the files returned?? Thanks for your input. **PS: The new ZipArchive() library/class is not available on our production environment so I chose to use the Unix utility ZIP instead.** I've heard about a function that does so, but I did not have much luck implementing it. Is is possible for me to get the time my file was modified in this script? Code: [Select] <html><head> <title>RCM File List</title> <link rel="stylesheet" type="text/css" a href="/rcm/stylesheet.css"> </head> <body> <h1>Files in RCM Directory</h1> <?php $dir="C:/xampp/htdocs/rcm/*txt"; foreach(glob($dir) as $file) { $list = "<li><a href='readfile2.php'>Filename: $file</a></li><br>"; } ?> <ul> <?php echo $list; ?> </ul> </body> </html> I'm having a problem with getting the timestamp to attach to the filename. Currently when it's uploaded in the database it says $timestamp in front of the filename instead of the time. Scroll down towards the bottom of the code to see it. Thanks for your help! $username = $_GET['username']; $item_id = $_GET['id']; define( 'DESIRED_IMAGE_WIDTH', 150 ); define( 'DESIRED_IMAGE_HEIGHT', 150 ); $source_path = $_FILES[ 'thumb' ][ 'tmp_name' ]; $timestamp = time(); // // Add file validation code here // list( $source_width, $source_height, $source_type ) = getimagesize( $source_path ); switch ( $source_type ) { case IMAGETYPE_GIF: $source_gdim = imagecreatefromgif( $source_path ); break; case IMAGETYPE_JPEG: $source_gdim = imagecreatefromjpeg( $source_path ); break; case IMAGETYPE_PNG: $source_gdim = imagecreatefrompng( $source_path ); break; } $source_aspect_ratio = $source_width / $source_height; $desired_aspect_ratio = DESIRED_IMAGE_WIDTH / DESIRED_IMAGE_HEIGHT; if ( $source_aspect_ratio > $desired_aspect_ratio ) { // // Triggered when source image is wider // $temp_height = DESIRED_IMAGE_HEIGHT; $temp_width = ( int ) ( DESIRED_IMAGE_HEIGHT * $source_aspect_ratio ); } else { // // Triggered otherwise (i.e. source image is similar or taller) // $temp_width = DESIRED_IMAGE_WIDTH; $temp_height = ( int ) ( DESIRED_IMAGE_WIDTH / $source_aspect_ratio ); } // // Resize the image into a temporary GD image // $temp_gdim = imagecreatetruecolor( $temp_width, $temp_height ); imagecopyresampled( $temp_gdim, $source_gdim, 0, 0, 0, 0, $temp_width, $temp_height, $source_width, $source_height ); // // Copy cropped region from temporary image into the desired GD image // $x0 = ( $temp_width - DESIRED_IMAGE_WIDTH ) / 2; $y0 = ( $temp_height - DESIRED_IMAGE_HEIGHT ) / 2; $desired_gdim = imagecreatetruecolor( DESIRED_IMAGE_WIDTH, DESIRED_IMAGE_HEIGHT ); imagecopy( $desired_gdim, $temp_gdim, 0, 0, $x0, $y0, DESIRED_IMAGE_WIDTH, DESIRED_IMAGE_HEIGHT ); // // Render the image // Alternatively, you can save the image in file-system or database // header( 'Content-type: image/jpeg' ); imagejpeg( $desired_gdim, "image_files/".'$timestamp'.$_FILES["thumb"]["name"] ); mysql_connect("localhost", "root", "", "") or die(mysql_error()); mysql_select_db("") or die(mysql_error()); $timestamp = time(); $item_image = '"$timestamp"'.$_FILES['thumb']['name']; $sql="UPDATE product SET thumb='$item_image' WHERE id = '$item_id'"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); Hi; why does this snippet of code doesn't measure the time required to include the file in milliseconds. The problem is unknown for me because the variable $diff always have the wrong value. Here is the code :
<?php $start = microtime(true); include('/path/to/my/script.php'); $end = microtime(true); $diff = ($end-$start)*1000; echo 'The script took ' . $diff . 'ms to proceed.'; ?>The problem is that the variable $diff return a big number instead of a couple of milliseconds, for example it return a value such as 1416110398494 which is illogical why ? Regards Purpose: To get time zone of a remote file in my time zone. I have to download a file daily (mp3, don't worry its legal!) from BBC. Problem is that sometimes BBC doesn't update the file and i have to download entire file to check if it has been updated or not. Hence i decided to code a page that gives me date and time of that remote file. I have successfully compiled the code (that i got from internet). But the time returns in EST. I want the time in IST (indian std time Asia/Calcutta). CURLINFO_FILETIME has bee used. Below is code. Pls suggest me how to convert EST to IST - Warning: I am a newbie. But i can follow instructions Code: [Select] <?php $curl = curl_init('http://wsdownload.bbc.co.uk/hindi/tx/32mp3/din_bhar.mp3'); //don't fetch the actual page, you only want headers curl_setopt($curl, CURLOPT_NOBODY, true); //stop it from outputting stuff to stdout curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // attempt to retrieve the modification date curl_setopt($curl, CURLOPT_FILETIME, true); $result = curl_exec($curl); if ($result === false) { die (curl_error($curl)); } $timestamp = curl_getinfo($curl, CURLINFO_FILETIME); if ($timestamp != -1) { //otherwise unknown echo "BBC Hindi was last modified" . date("d-m-Y h:i:s A T", $timestamp); //etc } ?> I have used it with custom getRemoteFileSize function he - Code: [Select] http://island.web44.net/bbc.php This code works when theres no predefined value however I'm trying to modify it in case there IS a value from the DB which is from the " . $row2['content'] . " data. Code: [Select] echo "<select name=" . $row2['ID'] . " id=" . $row2['ID'] . " class=dropdown biofield title=" . $row2['fullName'] . " >"; echo "<option value= >None</option>"; if ($styleID == 1 || $styleID == 2 || $styleID == 6) { $charactersQuery = " SELECT characters.ID, characters.characterName FROM characters WHERE characters.styleID = 3 ORDER BY characters.characterName"; } else { $charactersQuery = " SELECT characters.ID, characters.characterName FROM characters WHERE characters.styleID IN (1,2,6) ORDER BY characters.characterName"; } $charactersResult = mysqli_query ( $dbc, $charactersQuery ); // Run The Query while ( $row3 = mysqli_fetch_array ($charactersResult, MYSQLI_ASSOC)) { echo "<option value=" . $row3['ID'] . ">" . $row3['characterName'] . "</option>\r"; } echo "</select>"; I normally use something like this but with the other code not sure how to modify it to work the same way. Code: [Select] while ( $champion_row = mysqli_fetch_array ( $charactersResult, MYSQL_ASSOC ) ) { print "<option value=\"".$champion_row['ID']."\" "; if($champion_row['ID'] == $row['champID']) { print " SELECTED"; } print ">".$champion_row['characterName']."</option>\r"; } Hey everyone. Currently I have a site set up where I manually edit the txt file and the site pulls it from the text file and displays via php. I wanted to automate it by creating one file which contains the sunset times for the whole year, and have php determine todays date and then display the corresponding sunset time. Can someone please point me in the right direction? maybe it can be set up in a way where each line in the txt file represents the day of the year. ex: Jan 1 would be line 0, Feb 1's sunset time would be on line 31 etc. Thanks Hello Everyone, I am on windows server and In my ini file server time zone declared as below
[server_settings] but my application installed on another timezone eg: 'America/Los_Angeles' time zone. using date_default_timezone_get() i am always getting Europe/London timezone as it's declared in ini file. How to get local timezone(wherever application is installed) here? Thanks Krish I am trying to get this script to display the date like Dec 17, 2010 and have the search function work too. If I try to change the date the search malfunctions and if I take the date function away the date is 2010 12 17 I thought we had this nailed down the other day but in my excitement I neglected to test the city search. Here is the script. <?php $find = trim($_GET['find']); $field = $_GET['field']; if($find && $field) { // we have search form submitted // check for values to prevent sql injection $valid_fields = array("venue_state", "venue_city", "start_date"); if(!in_array($field, $valid_fields)) die("Error: Invalid field!"); //connect mysql_connect("localhost", "arts_cshow", "TrPh123Yuo") or die(mysql_error()); mysql_select_db("arts_shows") or die(mysql_error()); echo "<h2>Search Results for $find in $field</h2>\n"; $find = addslashes($find); $result = mysql_query("SELECT * FROM craft_shows WHERE $field LIKE '%$find%'"); if(mysql_num_rows($result) == 0) { echo "<p>0 matches found.</p>"; } else { echo "<table><tr><td class=\"shows\">"; $sql = "SELECT *, DATE_FORMAT(`start_date`, '%b %e, %Y') AS s_date FROM craft_shows"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { echo "<a href='/show_submits/show_detail.php?id={$row['id']}'>Details</a>\n"; echo $row['venue_state'] . " {$row['s_date']} {$row['show_name']} {$row['venue_city']}<br>\n"; } echo "</td></tr></table>\n"; } } ?> thanks I am currently trying to build a contact form for a website. I have been given a script to use that was used on another site but it has an iff statement in it to change the strEmail according to the location and requirement. Thank you for writing this script. It has been most helpful in doing a search for a website I manage. Everything is working fine but I would like some help in modifying the "$results[] = " line. For instance, I would like to show or hide the address of a business if a data value is set to 1 if set to 0 then hide. Same for the business web address. if ( $row_memberrs['WebAddress'] != NULL ) { echo <a href=\"{$row['WebAddress']}\" target=_blank>Visit our website</a>; } I am a newbie to php and would appreciate any help you can give me. Here is a link to the search page http://www.wildwoodba.org/searchsite.php If it is not too much trouble I would like to hide the check boxes and make it search the body, title or disc for the words entered. Thank you for your help. |