$p){ if($p['id']===$id){ if(!empty($p['image'])){ $f=__DIR__.$p['image']; if(file_exists($f)) unlink($f); } unset($posts[$k]); } } savePosts($postFile,array_values($posts)); header("Location: ./"); exit; } $text=trim($_POST['text']??''); $image=''; if( !empty($_FILES['image']['tmp_name']) ){ $tmp=$_FILES['image']['tmp_name']; $type= mime_content_type($tmp); if( str_starts_with( $type, 'image/' ) ){ $name= uniqid() .'.jpg'; $path= $uploadDir .'/'.$name; move_uploaded_file( $tmp, $path ); $image= '/data/uploads/' .$name; } } if( $text || $image ){ array_unshift( $posts, [ 'id'=>uniqid(), 'text'=>$text, 'image'=>$image, 'time'=>time() ] ); savePosts( $postFile, $posts ); } header("Location: ./"); exit; } $posts= loadPosts( $postFile ); ?>