I am trying to display the most recent images added to a portfolio items folder to use as featured images - The code below is doing a good job of getting an image from the specified folder, however it's not displaying the last one to be uploaded… any suggestions?   &lt;?php $files= glob('./uploads/test/'. $user-&gt;id .'/'.$item-&gt;id.'/*'); $count = 0; $user_avatar = '/images/noimage.jpg';  if (!file_exists('./uploads/test/'. $user-&gt;id .'/'.$item-&gt;id.'/*')) {    $user_avatar = '/images/noimage.jpg'; }    // otherwise continue foreach ($files as $file) { $count++; if ($count &gt; 0 &amp;&amp; is_file($file)) {  $user_avatar = $file; }  } ?&gt;
12041
I'm trying to display an array of files in order of date (last modified).  I have done this buy looping through the array and sorting it into another array, but is there an easier (more efficient) way to do this?
122510
I have found a  very similar to this, which I thought would solve my problem.   However, after changing my .htaccess file, with index.php on the end of the list, and then index.php as the only entry, I still cannot get index.php to display.  Every other page works fine, but I don't know how to fix this.  Thanks.
1270
For the purpose of testing, I'd like count how many images files are inside a directory, separating each image file type by file extension (jpg="yes". This because later it will be useful for another script that will execute an action on each file extension). Can I use something like the following for only JPEG files?  jpg="" count=`ls -1 *.jpg 2&gt;/dev/null | wc -l` if [ $count != 0 ] then echo jpg files found: $count ; jpg="yes" fi   Considering file extensions jpg, png, bmp, raw and others, should I use a while cycle to do this?
259
I sometimes browse erotic media files but I would like to avoid having them appear in files &amp; folders / recent. How can I do that?  The old "making .recently-used.xbel a folder" trick from 10.10 and older doesn't work any more.   Plus I'd prefer to turn off tracking only temporarily.  I also prefer not to use a separate user for this, as switching users sometimes isn't fast enough.
37104
On the PHP website, the only real checking they suggest is using is_uploaded_file() or move_uploaded_file(), . Of course you usually don't want user's uploading any type of file, for a variety of reasons.  Because of this, I have often used some "strict" mime type checking. Of course this is very flawed because often mime types are wrong and users can't upload their file. It is also very easy to fake and/or change. And along with all of that, each browser and OS deals with them differently.  Another method is to check the extension, which of course is even easier to change than mime type.  If you only want images, using something like getimagesize() will work.  What about other types of files? PDFs, Word documents or Excel files? Or even text only files?  Edit: If you don't have  or  and system("file -bi $uploadedfile") gives you the wrong file type, what other options are there?
22745
Trying to learn more about creating my own themes and not using any plugins I wanted an ability to display all the images in a post excluding the thumbnail in my single-foobar.php file and I can do that with:  &lt;?php if ( have_posts() ) : while ( have_posts() ) : the_post();      $thumb_ID = get_post_thumbnail_id( $post-&gt;ID );  $args = array(    'post_type' =&gt; 'attachment',    'numberposts' =&gt; -1,    'post_status' =&gt; null,    'post_parent' =&gt; $post-&gt;ID,    'exclude' =&gt; $thumb_ID   );  $attachments = get_posts( $args );  if ( $attachments ) {     foreach ( $attachments as $attachment ) {        echo '&lt;div class="portproject"&gt;';        $image_res = wp_get_attachment_image( $attachment-&gt;ID, ' img-responsive' );        echo $image_res;        echo '&lt;/div&gt;';       }  }  else { ?&gt;     &lt;span&gt; No pictures loaded at this time&lt;/span&gt;  &lt;?php } endwhile; endif; ?&gt;   However, when I apply my static HTML and then try to call get_the_content() with:  &lt;?php  $content = get_the_content(); $content = preg_replace("/&lt;img[^&gt;]+\&gt;/i", "(image) ", $content);           $content = apply_filters('the_content', $content); $content = str_replace(']]&gt;', ']]&gt;', $content); echo $content; ?&gt;   it removes the images but leaves a (image) in the post with spaces then displays the remaining text. I did find a similar  but it suggests using get_the_content() but that strips all the styling from the post.  So my question is how can I strip images from the_content()?  I did find "" from my searches but that still uses the get_the_content() approach.
60712
I need to save an image from a PHP URL to my PC. Let's say I have a page, http://example.com/image.php, holding a single "flower" image, nothing else. How can I save this image from the URL with a new name (using PHP)?
84856
I want WordPress to return the first post image or a default image if no featured image has been set. My theme uses the_post_thumbnail many times, so I don't want to go through and change all references to a new function. I'd rather filter the core. Here's what I've added to functions.php:  add_filter('post_thumbnail_html', 'my_thumbnail_html', 10, 5);  function my_thumbnail_html( $html, $post_id, $post_thumbnail_id, $size, $attr ) {     global $post, $posts;     if (has_post_thumbnail() ) {         echo get_the_post_thumbnail( null, $size, $attr );     }     else {         $first_img = '';         ob_start();         ob_end_clean();         $output = preg_match_all('/&lt;img.+src=[\'"]([^\'"]+)[\'"].*&gt;/i', $post-&gt;post_content, $matches);         $first_img = $matches [1] [0];         if(empty($first_img)){             $first_img = get_bloginfo("template_url") . '/images/default.gif';         }         return $first_img;     } }   How do I hook this correctly?
29780
I am trying to convert a bunch of images to thumbnails that might be in several subdirectories, and save a copy of the image as a thumbnail inside the subdirectory, but I can't figure out the syntax. Any advice would be welcome.   convert test/*/*.jpg -50x50 test/*/*_thumb.jpg
97322
I want to download the images shown in a web page, for example , (the ones under the All Artworks tab), and store them in a folder (e.g. /home/boomer/GH/A_nou/).  How can I achieve this?  I can use wget or curl for that, but sadly I have no idea of what to do with them.  Also I don't want the intermediate images, (banners, logos, etc.), only full size images for everything under the artwork section.
71165
I don’t know if this is a bug or is this how the images work, hosted on imgur. It basically adds a query string. I added a profile pic as gif but it doesn’t work as how gif images work. If I goto the image url it works fine.  My Profile:   Image URL on profile:   Actual animated image Url without Query String (working):   Is this how images hosted on imgur work or is this something else?
97044
Stack Overflow  to work through , but the custom avatars (uploaded files, not those from gravatar) are even then fetched from  using standard   (which generates warning in browsers and is not a very good practice). As those images are also available   it could be just a service misconfiguration.  Is there a technical (or any other) reason why they couldn't be fetched using HTTPS?
101504
I added this code but when I upload 1 image, then 4 images of 1 image are uploaded, what is happening IMAGES : Not proper working PDF file upload : work fine Doc file upload : work fine rvt file upload : not working Now I am trying to upload multiple files my HTML code is: &lt;input type=&quot;file&quot; name=&quot;my_file_upload[]&quot; id=&quot;my_file_upload[]&quot; multiple=&quot;multiple&quot;&gt;  Code &gt; file custom.php if ( $_FILES ) {  $files = $_FILES[&quot;my_file_upload&quot;];   foreach ($files['name'] as $key =&gt; $value) {                     if ($files['name'][$key]) {              $file = array(                  'name' =&gt; $files['name'][$key],                 'type' =&gt; $files['type'][$key],                  'tmp_name' =&gt; $files['tmp_name'][$key],                  'error' =&gt; $files['error'][$key],                 'size' =&gt; $files['size'][$key]             );              $_FILES = array (&quot;my_file_upload&quot; =&gt; $file);              foreach ($_FILES as $file =&gt; $array) {                               $newupload = my_handle_attachment($file,$pid);              }         }      }  }  Function.php File code function my_handle_attachment($file_handler,$post_id,$set_thu=false) { // check to make sure its a successful upload if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();   require_once(ABSPATH . &quot;wp-admin&quot; . '/includes/image.php');  require_once(ABSPATH . &quot;wp-admin&quot; . '/includes/file.php');  require_once(ABSPATH . &quot;wp-admin&quot; . '/includes/media.php');   $attach_id = media_handle_upload( $file_handler, $post_id ); if ( is_numeric( $attach_id ) ) {   update_post_meta( $post_id, '_my_file_upload', $attach_id );  } return $attach_id; }
86451
I've got a script that dynamically calls and displays images from a directory, what would be the best way to paginate this?  I'd like to be able to control the number of images that are displayed per page through a variable within the script.  I'm thinking of using URL varriables (ie - ) but am unsure how to go about this.  Thanks for the help.
12556
Basically on my site I have a bunch of song lyrics and in a static page I want to show them listed by album  and album position of the song and I have two custom fields with that data, sd_album_title and `sd_album_track_n. Plus some of the songs don't have an album yet, so both values are void, and I wish to list those ones at the foot of the others, sorted by alphabetical order.  The latest thing I tried at least to sort everything by the two field is this one:  $key = 'sd_album_title'; $themeta = get_post_meta($post-&gt;ID, $key, TRUE);  add_filter( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $query ) {     if ($themeta != '') {         $query-&gt;set( 'post_type', 'lyric' );         $query-&gt;set( 'meta_key', 'sd_album_title' );         $query-&gt;set( 'orderby', 'meta_value' );         $query-&gt;set( 'order', 'ASC' );         $query-&gt;set( 'meta_query', array(               array(                     'key' =&gt; 'sd_album_title'               ),               array(                     'key' =&gt; 'sd_album_track_n',                     'value' =&gt; 'target_value',                     'compare' =&gt; '&gt;=',                     'type' =&gt; 'numeric'               )         ));     }     return $query; }  $getlist= 'my_get_posts'; $posts = get_posts( $getlist );   And my intention was to put an else at the end of it with an array ordered by title for the other songs, but it returns nothing as it is. Could something like this work with some corrections or am I on a totally wrong path?
14996
In Drupal 6 I used to make every sort of customised markup for CCK fields with multiple values. Usually this happened when I wanted to lay out thumnails for a gallery inside a table: I used to go into the relevant tpl.php file, grab the relevant $field_fieldname variable, loop through it, and print out the 'view' key for it, which contained the styled thumbnail, often linked to the original image and whatever.  Now, I'm a bit confused on how this should be done in Drupal 7. For now, I set up a suboptimal solution that goes like  &lt;section class="gallery"&gt;     &lt;div class="row first"&gt;     &lt;?php foreach($content['field_gallery'] as $k =&gt; $v) : ?&gt;         &lt;?php if(is_numeric($k)) : ?&gt;             &lt;?php echo render($v) ?&gt;             &lt;?php if((($k+1) % 4) == 0) : ?&gt;     &lt;/div&gt;&lt;div class="row"&gt;             &lt;?php endif ?&gt;         &lt;?php endif ?&gt;     &lt;?php endforeach ?&gt;     &lt;/div&gt; &lt;/section&gt;   but it's obviously wrong. I can't seem to get my head around this, even after having read lots of docs about the Field API and theming for D7. Ideas?
98065
I need to display some featured image info on post page. Among other info I need to display file size of image (featured image of post).  I tried this function inside single.php.  &lt;?php function getSize($file){    $bytes = filesize($file);    $s = array('b', 'Kb', 'Mb', 'Gb');    $e = floor(log($bytes)/log(1024));    return sprintf('%.2f '.$s[$e], ($bytes/pow(1024, floor($e)))); } ?&gt;   and to echo that:  &lt;?php echo getSize('/wp-content/uploads/2014/06/some-file-name.jpg'); ?&gt;   It works, but I need help to make ti automatically grab featured image url, not to manually enter it in code?  For example I use this to echo featured image ("full") url:   &lt;?php  if ( has_post_thumbnail()) {    $full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post-&gt;ID), 'full'); echo $thumb_image_url[0];  } ?&gt;    Could you please help to combine it, or to provide me with another solution?