• 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.