Search the Community
Showing results for tags 'dir'.
-
I am having trouble trying to save my image file names to mysql after reading a dir. I am trying to use the file below. Any help would be appreciated. I was originallly getting the files to list but they we not showing up in the database. Now the page shows up blank. <?php require("config_0.php"); // Connect to server and select database. mysql_connect($dbhost, $dbuser, $dbpass)or die("cannot connect"); mysql_select_db("test")or die("cannot select DB"); $files = glob("images/*.jpg"); for ($i=1; $i<count($files); $i++) { $num = $files[$i]; $sql="INSERT INTO images (url) VALUES ('$num')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } echo '<img src="'.$num.'" alt="random image">'." "; } ?>
-
i have this sample script i would like to add to my existing php page to search a directory and display the results with a download link. here is the script any ideas where am going wrong? <?php $dir = 'my_directory'; $exclude = array('.','..','.htaccess'); $q = (isset($_GET['q']))? strtolower($_GET['q']) : ''; $res = opendir($dir); while(false!== ($file = readdir($res))) { if(strpos(strtolower($file),$q)!== false &&!in_array($file,$exclude)) { echo "<a href='$dir/$file'>$file</a>"; echo "<br>"; } } closedir($res); ?> <form action="my_phpfile" method="get"><input name="q" type="text"> <input type="submit"></form>