Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'files'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Single Editions
    • Modern Javascript: Develop and Design
    • The Yii Book
    • Effortless Flex 4 Development
    • Building a Web Site with Ajax: Visual QuickProject
    • Ruby: Visual QuickStart Guide
    • C++ Programming: Visual QuickStart Guide
    • C Programming: Visual QuickStart Guide
    • Adobe AIR: Visual QuickPro Guide
  • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
    • PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
  • PHP for the Web: Visual QuickStart Guide
    • PHP for the Web: Visual QuickStart Guide (5th Edition)
    • PHP for the Web: Visual QuickStart Guide (4th Edition)
    • PHP for the Web: Visual QuickStart Guide (3rd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (2nd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (1st Edition)
  • Effortless E-commerce with PHP and MySQL
    • Effortless E-Commerce with PHP and MySQL (2nd Edition)
    • Effortless E-Commerce with PHP and MySQL
  • PHP Advanced: Visual QuickPro Guide
    • PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
    • PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
    • PHP Advanced: Visual QuickPro Guide
  • MySQL: Visual QuickStart Guide
    • MySQL: Visual QuickStart Guide (2nd Edition)
    • MySQL: Visual QuickStart Guide (1st Edition)
  • Other
    • Announcements
    • Newsletter, Blog, and Other Topics
    • Forum Issues
    • Social

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 2 results

  1. Hi Larry I thought that I'd post this as it might help other php-ers. I have a website which has many images. To facilitate the download of images, I save a reduced image under a directory name e.g. images/activities/P3451098.jpg for thumbnails and slideshows as well as the full size in e.g. images/raw/P3451098.jpg. Then I can offer an enlarged image using <a href = ***><img src...... target = "_blank"> etc. The problem is that as I send the images up using FTP (Filezilla) I can't be sure if all of the reduced images have the corresponding full sized images thanks to advanced dementia. Therefore, I have written a short routine to compare the two directories.... COMMENTS: 1) I was confused at first as to why it didn't work properly until I discovered that glob() is case sensitive, so that it wasn't finding .JPGs so had to run it twice (there is a variety of both depending on which camera they came from). 2) The search routine is not very elegant as it runs through all of the raw files even though it may have found a match in the first file. 3) I know that I could use glob(images/raw/*.*) instead of glob(images/raw/*.*) and in this case it wouldn't make any difference as all files in these directories are .jpgs - it just seems more precise to use *.jpg. I would appreciate any comments from anybody..... <?php //Declare variable $found to avoid undefined variable errors $found = "No"; //Call header which handles security and error messages include ('adminheader.php'); //Create an array $images which lists all of the relevant image directories on the server.. $images = array('4X4', 'activities', 'almonds', 'alojamiento', 'altiplano', 'archery', 'area', 'artifacts', 'baza', 'castillejar', 'castril', 'caving', 'fiestas', 'flowers', 'history', 'huescar', 'kayaking', 'index', 'markets', 'mountaineering', 'mountains', 'museums', 'photography', 'puebla', 'rafting', 'village', 'wildlife', 'activities/activities', 'activities/caving', 'activities/kayaking', 'activities/mountaineering', 'activities/outdoors', 'activities/rafting'); //Create array $raw which will be a listing of all of the large image files on the server $raw = glob('images/raw/*.jpg'); $raw2 = glob('images/raw/*.JPG'); //Work through the $images array so as to compare whether there is a large matching file in the 'raw' directory... foreach($images as $key => $category) { //Start with a header to ID each category.... echo 'CATEGORY:... ' . $category . '<br /><br />'; //Now create a variable ($getlisting) to be able to call only the category that we are interested in... $getlisting = 'images/' . $category . '/*.jpg'; //create an array of the files in this category.. $listing = glob($getlisting); //Run through the $raw array to see if it contains a file that matches the file in the category... foreach($listing as $key => $value) { //Create variable to use in str_replace.. $directory = 'images/' . $category . '/'; // Remove the unwanted directory details.... $value = str_replace($directory, "", $value); //Reduce any JPGs to jpgs... $value = strtolower($value); //Run through the $raw array to find a match.. foreach($raw as $key => $rawvalue) { //Get rid of directory details from $rawvalue... $rawvalue = str_replace("images/raw/", "", $rawvalue); //Bring any .JPGs to .jpgs.... $rawvalue = strtolower($rawvalue); //Do comparison. If raw image matches reduced image then do nothing.. if ($value == $rawvalue) { //If the small and large files match then switch variable $found to 'on'.... $found = "Found"; } } //Run through the $raw array to find a match.. foreach($raw2 as $key => $rawvalue) { //Get rid of directory details from $rawvalue... $rawvalue = str_replace("images/raw/", "", $rawvalue); //Bring any .JPGs to .jpgs.... $rawvalue = strtolower($rawvalue); //Do comparison. If raw image matches reduced image then do nothing.. if ($value == $rawvalue) { //If the small and large files match then switch variable $found to 'on'.... $found = "Found"; } } //If small and large files don't match, then print out the filename .. if ($found != "Found") { echo $value . "<br /><br />"; } //reset $found to "Not found".. $found = "No"; } //Close individual Category foreach echo "<br /><br />"; } //Close all category foreach echo "ALL DONE!"; include ('footer.php'); ?>
  2. For the list_dir.php script, line 42 sets conditions to determine if an item should be written or not. The conditions are: if ( (is_file($search_dir . '/' . $item)) AND ((substr($item, 0, 1) != '.') ) I rewrote the condition to fit my preferences, and I will be referring to my version when asking my question, so if my code is wrong that could be the problem. But to the best of my knowledge, they are equivalent. if (is_file($search_dir . '/' . $item) && sub_str($item, 0, 1) != '.') The conditions are quite obvious, and stated in the text. But when I execute the code, no files are shown, and I checked the HTML to make sure. It is the script. I began debugging and discovered that when I remove the second part of the condition && sub_str($item, 0, 1) != '.' it works fine. That makes sense in a way, because it is less restrictive, but none of my file names begin with a period. And what is odd is that I do not encounter a similar problem with directories. When the same 'second part' of the condition is removed for the directory section, the predicted outcome occurs (the parent '..' and current '.' directories appear). I would like to point out that I am running my server off of my Linux (Ubuntu 11.10) computer - implying that I am not running Windows or Mac OS X. My webroot is the 'php' directory with this path: /var/www/php/ Hypotheses: A permissions issue Code in the book is not applicable to my server's operating system The php.ini file is configured differently than the author's I do not know how to test any of the hypotheses, but I imagine I would be able to test the first one by using chmod, but I do not full understand what 'group' and 'other' mean, or what user PHP is under, or what permissions should be sufficient. The entirety of my script follows. <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="default.css" /> <title>Directory Contents</title> </head> <body> <?php // Set directory name and scan $search_dir = '.'; $contents = scandir($search_dir); // List directories print '<h2>Directories</h2> <ul>'; foreach ($contents as $item) { if (is_dir($search_dir . '/' . $item) && substr($item, 0, 1) != '.') { print '<li>' . $item . '</li>' . "\n"; } } print '</ul>'; // Create table for files print '<h2>Files</h2> <table> <tr> <td>Name</td> <td>Size</td> <td>Modified</td> </tr>'; // List files foreach ($contents as $item) { if (is_file($search_dir . '/' . $item)) // && (sub_str($item, 0, 1) != '.') was removed { $fs = filesize($search_dir . '/' . $item); $lm = date('F, j, Y', filemtime($search_dir . '/' . $item)); print " <tr> <td>$item</td> <td>$fs bytes</td> <td>$lm</td> </tr>"; } } print '</table>'; ?> </body> </html> This HTML is the result of including the second part of the condition: <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="default.css" /> <title>Directory Contents</title> </head> <body> <h2>Directories</h2> <ul><li>css</li> <li>template</li> </ul><h2>Files</h2> <table> <tr> <td>Name</td> <td>Size</td> <td>Modified</td> </tr> I do not know why it does not print code after the foreach statement, or even after the closing php tag.
×
×
  • Create New...