PHP - Help With $readdir Script I Made
Hey guys basically with a simple script that I made I need some help with it's doing my head in.
What i'm trying to do is allow multiple filetypes to be shown by readdir, i want both .zip and .rar to be in the list, not just .zip how would i add .rar in this method as well to be visible on readdir? <?php $dirname = "/home/test/"; $dir = opendir($dirname); $extension = array_pop(explode(".", $file)); ?> <?php while(false != ($file = readdir($dir))) { if ($file != "." && $file != ".." && array_pop(explode(".", $file)) == "zip") { echo(" <b>» <a href='$dirname$file'>$file - Download</a> <br /> </b> "); } } ?> Similar TutorialsSorry for the noobie question, I am just a beginner still. I am trying to use the readdir function to echo back all the contents of a folder. The directory that I want to read back has 31 empty folders. I am able to get them to read back, but they are in a random order and there are two additional files at the top named "." and ".." -- any idea how to fix these? Here is my code and pictures: Quote $path = "c:/test/"; if(is_dir($path)) { if($dir_handle = opendir($path)) { while($filename = readdir($dir_handle)) { echo "filename: {$filename}<br>"; } closedir($dir_handle); } } Hi folks, First time posting here and a bit of a novice at PHP, but am learning.... I am fiddling with a small bit of code to create a very basic php gallery (I'm sure everyone has at some point). I started off with a mysql intergrated one then thought I would try a new one without the mysql. Its working fine but I am just having one very strange problem. Basically, I started of with just /mygallery/index.php?w=... where ... = the location (physical folder) of photos. I use opendir to open the contents of w= and parse whether it is a directory or a file (then narrow it down to just images). If it is a dir, then I present it as a link to that folder (sub-album) if it is a photo, I present a thumb link to the image. Now I have added a mod_rewrite rule to allow my urls to be of the form 'mygallery/album/subalbum' this gets ocnverted into 'mygallery/index.php?w=album/subalbum' Now the funny bit. If I create a new folder in one of the subalbum, e.g. : mygallery/album/subalbum/<b>New Folder</b> the code works. i.e. when I point my browser at 'mygallery/album/subalbum' I get a link showing 'New Folder' But if I create a new folder of any other NAME it does not appear in the list!! So if I just rename 'New Folder' to 'New Folde' it drops of the web page!!! Now I am really not sure what the hell is going on... Hope someone can help. I will post my code if necessary. Thanks in advance! Jon Reynolds Hi all, I have a PHP function that reads JPG's from a folder that contains over 100,000 files. The problem I have is that the READDIR() function takes a while to list the contents due to the large number of files. I'm trying to speed up the process by using a filter and listing only the files I need. Example: list files with a timestamp for an entered date period. Code: [Select] $file >= '2012-04-02 OR $file <= '2012-03-04' This lists the JPG files but my modification to list files using a timestamp does not work nor can I find a way of seeing why it does not work. This has me stuck. Thank you in advance to anyone who can post some pointers. Code that lists JPGS only Code: [Select] <?php $path = 'imgs/'; function directory($dir,$filters) { $handle=opendir($dir); $files=array(); if ($filters == "all"){while(($file = readdir($handle))!==false){$files[] = $file;}} // 'all' filter is if you set to list ALL files and folders. if ($filters != "all") { $filters=explode(",",$filters); while (($file = readdir($handle))!==false) { for ($f=0; $f < sizeof($filters); $f++): $system=explode(".",$file); if ($system[1] == $filters[$f]){$files[] = $file;} endfor; } } closedir($handle); return $files; } $files = directory($path, "jpg"); //for multiple file types just separate the file extensions by commas foreach ($files as $value) { echo $value.'<br>'; } ?> I have added the filter Code: [Select] && filemtime($file) >= strtotime('2010-04-12') but it does not work. Code: [Select] <?php $path = 'imgs/'; function directory($dir,$filters) { $handle=opendir($dir); $files=array(); if ($filters == "all"){while(($file = readdir($handle))!==false){$files[] = $file;}} // 'all' filter is if you set to list ALL files and folders. if ($filters != "all") { $filters=explode(",",$filters); while (($file = readdir($handle) && filemtime($file) >= strtotime('2010-04-12'))!==false) { for ($f=0; $f < sizeof($filters); $f++): $system=explode(".",$file); if ($system[1] == $filters[$f]){$files[] = $file;} endfor; } } closedir($handle); return $files; } $files = directory($path, "jpg"); //for multiple file types just separate the file extensions by commas foreach ($files as $value) { echo $value.'<br>'; } ?> Hi all I hope I have come to the right place. My system reads files stored on a drive and lists them to users through plain HTML, I made it 11 years ago and have to refresh my memory. My problem is that filenames seem to come in different formats, to how to decode/encode them is an issue...
My users use Scandinavian letters (æøåäöüõ) and it seems like one filename is in one format and another in another format. There is no logic to what format the filenames comes it. All files are ok and downloads as they should, they just dont list well. Any idea how I can handle this issue?
I've had a bit of a search around to see if this is possible but have yet to find something. I'm looking to be able to offset the results from opendir or similar function without returning all the files/folders. In other words i'd like to display the file/folder results over multiple pages when there are a lot of files/folders to display. Is this at all possible? My new host (Siteground) cloned and moved my html/php site (built by the previous owner) from Heart Internet server. All of the site works except for the sidebar, I get these 2 errors. Anyone shed any light on these at all?
Warning: readdir(): supplied argument is not a valid Directory resource in /home/customer/www/dunster.org.uk/public_html/include/toolbox.php on line 97
Warning: opendir(/home/sites/dunster.org.uk/public_html//local_information) [function.opendir]: failed to open dir: No such file or directory in /home/customer/www/dunster.org.uk/public_html/include/toolbox.php on line 86 Hi! I have started a big project with some of my friends. Its some kind of CMS system. Now, for quick commands we wanted something like cmd on windows. Is it possible to build a script that would be something like cmd/a console. Of course it would be a webpage and not a separate window. I could do this myself with a input field and a form using the POST method. But I wouldn't wan't to refresh the page every time I run a command. So something that works like the input field, form with the POST method, but without needing to refresh every time. Ask if I didn't make it clear enough! Regards Kevin
hello i am learning php a newbie .
// this is the user input / textdata
if(isset($_POST['textdata']))
// i added this line
// i changed this line below
fwrite($fp, $data);
thank you in advance. Edited November 21, 2019 by thehubclickleft out info so I am about to start on a small object oriented project, for practice/learning etc. I have 5 files in a folder called "objects" : (obj1.php obj2.php obj3.php obj4.php obj5.php) . I then created a "classloader.php" with the following code: Code: [Select] <?php include "objects/obj1.php"; include "objects/obj2.php"; include "objects/obj3.php"; include "objects/obj4.php"; include "objects/obj5.php"; ?> and then finally my main page (for the sake of testing): Code: [Select] <!DOCTYPE HTML> <head> <title>...</title> </head> <?php include "classloader.php"; ?> <body> <header></header> <nav></nav> <section> <?php object1(); object2(); object3(); object4(); object5(); ?> </section> <footer></footer> </body> What is the best way to handle the loading of objects in php? I think I am doing it somewhat wrong. Anyone lend me some more info here? thanks much. I have this query that fully works the way it is, but I am wondering if I am overdoing some things in it. I know this may be hard to tell without knowing the full relationship between all the tables in the query. I'm basically running 3 subqueries mostly based on a timestamp value and other specific clauses per subquery. Where the main query is only gathering based on the timestamp.
Like I said it works perfect from what I can verify by cross referencing the tables manually and checking the results the query returned. I just want to know if there is a better way to do all this.
SELECT `products`.`id` AS `pid`, `products`.`prod_name`, (SELECT COUNT(*) FROM `products` INNER JOIN `quote_deposits` ON `quote_deposits`.`product_id` = `products`.`id` INNER JOIN `quote_responses` ON `quote_responses`.`id` = `quote_deposits`.`q_id` WHERE `quote_responses`.`purchased` = 0 AND `quote_deposits`.`dep_date` >= $committed_start ) AS `committed`, (SELECT COUNT(`products`.`id`) FROM `products` INNER JOIN `quote_deposits` ON `quote_deposits`.`product_id` = `products`.`id` INNER JOIN `quote_responses` ON `quote_responses`.`id` = `quote_deposits`.`q_id` WHERE `quote_responses`.`purchased` = 1 AND `products`.`id` = `pid` AND `quote_deposits`.`dep_date` >= $committed_start ) AS `total_per_item`, (SELECT COUNT(`products`.`id`) FROM `products` INNER JOIN `quote_deposits` ON `quote_deposits`.`product_id` = `products`.`id` INNER JOIN `quote_responses` ON `quote_responses`.`id` = `quote_deposits`.`q_id` INNER JOIN `schedule` ON `schedule`.`deposit_id` = `quote_deposits`.`id` WHERE `quote_responses`.`purchased` = 0 AND `schedule`.`cancelled` != '' AND `products`.`id` = `pid` AND `quote_deposits`.`dep_date` >= $committed_start ) AS `total_cancelled` FROM `products` INNER JOIN `quote_deposits` ON `quote_deposits`.`product_id` = `products`.`id` WHERE `quote_deposits`.`dep_date` >= $committed_start GROUP BY `products`.`prod_name` ORDER BY `products`.`prod_name` ASC Hi all, I was playing a bit around with results from a database and thought lets give them a nice order in a table, so i thought i set the class per row, so my style sheet can finish it. This is what i got and it works. But some 6th sense whispers me that this can be done smoother. If anyone has ideas or tips let me know i have a lot to learn in php. and after all want to be a good code writer in php. // start table echo '<table class="users"> <th>name</th><th>email</th><th>active</th>'; $odd = 1; $num = 1; while($row = mysqli_fetch_assoc($result)){ // if( $odd == $num%2 ){ $evenodd = 'odd'; $num++; }else{ $evenodd = 'even'; $num++; } // echo'<tr class="'.$evenodd.'"><td>'.$row['name'].'</td><td>'.$row['email'].'</td><td>'.$row['accept'].'</td><tr>'; } echo '</table>'; thanks Hello everyone For a site of one of our customers our programmer created his own CMS which works OK at the site, but now the customer wants to shorten the URLS which are generated by the system. Is this easily possible? The programmer doesn't have the time to help us with it so that's why I try my luck here... I hope somebody can help me. Thanks!
Hello people! Well, I'm working on a site that has a financing simulator that asks for your data and a value related to cars, real estate and motorcycles. When simulating, it sends you to a page, calculating the closest result and sends your data to the database. However, he has a problem now. When you try to simulate, it no longer shows the result, it even loads the table but has no content, and the simulator form quickly pops up again. Check out an example at http://vitorconsorcios.com.br/simulador.php, below has the source code of the site. I've tried everything, but this is my last solution. What could be the cause of this? <?php include("injection.php"); /* if (isset($_POST['valorcon']) */ $valorcon = (int) tira_virgula_para_ponto( $_POST['valorcon'] ); $plano=anti_injection($_POST["plano"]); $tipo=anti_injection($_POST["tipo"]); $nomecon=anti_injection($_POST["nomecon"]); $telefone=anti_injection($_POST["telefone"]); $emailcon=anti_injection($_POST["emailcon"]); $cidadecon=anti_injection($_POST["cidadecon"]); if ($valorcon>0) { // Inseri a procura $tsql = " insert simulacao set plano='$plano' , tipo = '$tipo' , valor = $valorcon , nome = '$nomecon' , telefone = '$telefone' , email = '$emailcon' , cidade = '$cidadecon' "; //echo $tsql; //exit; $sql_insert = fbd($tsql,"","inserir simulacao"); ?> <div class="col-md-5"> <img src="img/simule.jpg" class="imagem" alt="Vitor Consórcios"> </div> <div class="col-md-7"> <h4>Confira a simualçao abaixo:</h4><br/> <table> <thead> <tr> <th>Descrição</th> <th>Valor do Crédito</th> <th>Valor da Parcela</th> <th>Valor da Meia Parcela</th> <th>Duração</th> </tr> </thead> <tbody> <?php $_SESSION['splano'] = $plano; $_SESSION['svalorcon'] = $valorcon; $_SESSION['stipo'] = $tipo ; if ($plano=='Crédito') { $tsql = " (SELECT * FROM `consulta` where tipo='$tipo' and credito>=$valorcon order by credito limit 2 ) UNION (SELECT * FROM `consulta` where tipo='$tipo' and credito<$valorcon order by credito desc limit 2 ) order by credito "; } ELSE { $tsql = " (SELECT * FROM `consulta` where tipo='$tipo' and parcela>=$valorcon order by parcela limit 2 ) UNION (SELECT * FROM `consulta` where tipo='$tipo' and parcela<$valorcon order by parcela desc limit 2 ) order by parcela "; } $_SESSION['sqlExecutar'] = $tsql ; //echo $tsql; //exit; $sql = fbd($tsql,"","Seleciona as empresa"); $num_rows = mysql_num_rows($sql); if ($num_rows>0) { ?> <script language= "JavaScript"> location.href="resultado.php" </script> <?php } ?> <script language= "JavaScript"> location.href="simulador.php" </script> <?php while($dados= mysql_fetch_array($sql)){ ?> <tr> <td align="left"><? echo $dados[descricao]; ?></td> <td>R$ <? echo valor_ponto_virgula( $dados["credito"] ); ?></td> <td>R$ <? echo valor_ponto_virgula( $dados["parcela"] ); ?></td> <td>R$ <? echo valor_ponto_virgula( $dados["parcela"]/2 ); ?></td> <td><? echo $dados["duracao"] ; ?></td> <?php } ?> </tbody> </table> </div> </div> <p> </p> <p> </p> </div> <?php } ELSE { ?> <h2>SIMULE AGORA SEU CONSÓRCIO!</h2><br/><br/> <div class="col-md-6"> <img src="img/simule.jpg" class="imagem" alt="Vitor Consórcios"> </div> <div class="col-md-1"></div> <form action="simulador.php" method="post" name="dados" id="dados" onSubmit="return validaform()"> <div class="col-md-5 esquerda"> Selecione o bem<br/> <select name="tipo" type="text" class="contat3" placeholder="Selecione o bem"> <option value="Imóvel"" style="background-color: #fff;">Imóveis</option> <option value="Automóvel"" style="background-color: #fff;">Automóveis</option> <option value="Moto" style="background-color: #fff;">Motos</option> </select><br/> Selecione o plano<br/> <select name="plano" type="text" class="contat3"> <option value="Crédito"" style="background-color: #fff;">Crédito</option> <option value="Parcela"" style="background-color: #fff;">Parcela</option> </select><br/> <input name="valorcon" type="text" id="valorcon" class="contat3" placeholder="Digite o valor" maxlength="1000" /><br/> <input name="nomecon" type="text" id="nomecon" class="contat3" placeholder="Nome" maxlength="1000" /><br/> <input name="telefone" type="text" onkeypress="Mascara('TEL',this,event);" type="text" id="telefone" class="contat3" placeholder="Telefone" /> <!--- <input name="tel2" type="text" id="tel2" onkeypress="Mascara('TEL',this,event);" /><br/> ---> <input name="emailcon" type="text" id="emailcon" class="contat3" placeholder="E-mal" maxlength="1000" /><br/> <input name="cidadecon" type="text" id="cidadecon" class="contat3" placeholder="Cidade" maxlength="1000" /> <br/><br/><br/> <a id="enviar-form" class="button solid-color" href="#">Enviar</a> <input type="submit" id="enviar-form-btn" style="display: none;" /> </div> </form> </div> <p> </p> <p> </p> </div> <?php } // 14-05-2018 ?> </div> </div>
Hi, I have a form with a submit button (Delete button). after I click the button I do few changes in database. Problem is that in this form, after the submit made, it still shows me old data that deleted.... So, I guess I need somehow to make a page refresh through a GET method. How do I do this? Thank u! Hello, Where can i find the source of the pre made php functions? Greets, Scuar. So I made a template class, it's very simple, pretty much allows the usage like so: $template = new template("blogpost"); $template->fillBraces(array( "TITLE" => "How to bathe your chimpanzee", "AUTHOR" => "Jim Bo James" )); $template->render(); Simple, uses tpl files, similar to what phpbb used a long time back, not sure if they still do. My main goal for this is to have a file that has something like this: {HEADER} {MAIN_CONTENT} {FOOTER} and the above usage to stay the same, however that would fill the main_content part, and the header and footer would be grabbed from header/footer tpl files. Any idea on suggestions? The full class is posted below. class template { protected $_viewContents; function __construct($viewName) { $this->_viewContents = file_get_contents(TEMPLATE.$viewName.TEMPLATE_EXT); return; } function sourceOf($fileName) { return @file_get_contents(TEMPLATE.$fileName.TEMPLATE_EXT); } function fillLayout() { } function fillBraces($information, $replacement=NULL) { if (is_array($information)) { foreach ($information as $key => $val) { $this->_viewContents = str_ireplace("{".$key."}", $val, $this->_viewContents); } return; } elseif ($replacement!=NULL) { $this->_viewContents = str_ireplace("{".$information."}", $replacement, $this->_viewContents); return; } } function render() { echo $this->_viewContents; } } Thanks! I have made a shopping cart where I can add items from my sql table. But I dont know how to send the table to my email. this is my cart.php Can someone give me some tips? Thanks in advance. you can also check it out on http://fhcs.be/cart-demo3/ <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Start the session session_start(); // Process actions $cart = $_SESSION['cart']; $action = $_GET['action']; switch ($action) { case 'add': if ($cart) { $cart .= ','.$_GET['id']; } else { $cart = $_GET['id']; } break; case 'delete': if ($cart) { $items = explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($_GET['id'] != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } $cart = $newcart; } break; case 'update': if ($cart) { $newcart = ''; foreach ($_POST as $key=>$value) { if (stristr($key,'qty')) { $id = str_replace('qty','',$key); $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($id != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } for ($i=1;$i<=$value;$i++) { if ($newcart != '') { $newcart .= ','.$id; } else { $newcart = $id; } } } } } $cart = $newcart; break; } $_SESSION['cart'] = $cart; ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>PHP Shopping Cart Demo &#0183; Cart</title> <link rel="stylesheet" href="css/styles.css" /> </head> <body> <div id="shoppingcart"> <h1>Your Shopping Cart</h1> <?php echo writeShoppingCart(); ?> </div> <div id="contents"> <h1>Please check quantities...</h1> <?php echo showCart(); ?> <p><a href="index.php">Back to bookshop...</a></p> </div> </body> </html> Hello, I need help with php, I don't understand what that could be , otherwise I run the page via a wampserver, I would be grateful for any kind of help. I have a list names in a database table in MySQL that I need to repeat the same search for on my system to get the associated information. Is there a Loop command or some type of trick to making a php script search table1.row1 then table1.row2 then table1.row3 etc. Basically using the row in the table as a variable for the other commands in the code. I really need some direction. Thanks. Hi I made a new design for my website and I made some changes. I want to use layout for my second site.
I'll like to know if my site is easier to browse through now and if you like the design better?. I test my site on internet explorer, chrome, and firefox. It is best to use site on better browsers like firefox and chrome to get a better experience of site. Thanks.
http://adjade.com
|