Title: set default image in PHP
Last modified: August 22, 2016

---

# set default image in PHP

 *  [sdrdavejohnson](https://wordpress.org/support/users/sdrdavejohnson/)
 * (@sdrdavejohnson)
 * [11 years, 10 months ago](https://wordpress.org/support/topic/set-default-image-in-php/)
 * Hi,
    I am trying to make a property rental site, and I want it to set a default
   image if no property photos are uploaded. I tried with an `if (empty($submitted_file))
   $submitted_file = "path/default.jpg";` , but it doesn’t seem to work, and I have
   very little experience with coding, so please help get this code right, so it
   uses a default image, if the user does not upload one:
 * > /* Upload Images */
   >  if($_FILES){ foreach( $_FILES as $submitted_file => $file_array){
   > if( is_valid_image( $_FILES[$submitted_file][‘name’] ) ){ $size = intval( $
   > _FILES[$submitted_file][‘size’] ); if( $size > 0 ){ if( $submitted_file == ‘
   > featured_image’ ){ /* Featured Image */ $uploaded_file_id = insert_attachment(
   > $submitted_file, $property_id, true ); if (empty($submitted_file)) $submitted_file
   > = “path/default.jpg”;
   >  /* Virtual Tour Image */
   >  if(empty($tour_video_image) && !empty($_POST[‘video-
   > url’])){ update_post_meta($property_id, ‘REAL_HOMES_tour_video_image’, $uploaded_file_id);}
   >  }else{
   >  /* Gallery Images */ $uploaded_file_id = insert_attachment( $submitted_file,
   > $property_id ); add_post_meta($property_id, ‘REAL_HOMES_property_images’, $
   > uploaded_file_id); } } }else{
   >  }
   >  } }
 * Thanks in advance.

The topic ‘set default image in PHP’ is closed to new replies.

## Tags

 * [default image](https://wordpress.org/support/topic-tag/default-image/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [template](https://wordpress.org/support/topic-tag/template/)

 * 0 replies
 * 1 participant
 * Last reply from: [sdrdavejohnson](https://wordpress.org/support/users/sdrdavejohnson/)
 * Last activity: [11 years, 10 months ago](https://wordpress.org/support/topic/set-default-image-in-php/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
